This question already has answers here:
MAC addresses in JavaScript
(8 answers)
Closed 9 years ago.
advance thanks those who gives me the great tips about how to find Physical address by using javascript.
Hope this helps!
function networkInfo(){
var wmi = new ActiveXObject ("WbemScripting.SWbemLocator");
var service = wmi.ConnectServer(".");
e = new Enumerator(service.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True"));
for(; !e.atEnd(); e.moveNext()) {
var s = e.item();
var macAddress = unescape(s.MACAddress);
}
return macAddress;
}
Related
This question already has answers here:
Javascript toFixed localized?
(4 answers)
Closed last month.
Hey dear Stackoverflow community,
I have a JS code that calculates various values based on an input value. It is output with a dot, but it should be displayed with a comma.
How can I customize the code for this?
<script>
var input = document.getElementById("invest_input-1");
input.oninput = function() {
var out = ((input.value * 0.38));
document.getElementById('invest_output_result-1').innerHTML = out.toFixed(2);
var out = ((input.value * 0.032));
document.getElementById('invest_output_result-2').innerHTML = out.toFixed(2);
var out = ((input.value * 0.03));
document.getElementById('invest_output_result-3').innerHTML = out.toFixed(2);
var out = ((input.value * 0.13));
document.getElementById('invest_output_result-4').innerHTML = out.toFixed(2);
};
</script>
Thank you so much!
Kind regards, Fabian
Based on the user's locale:
new Intl.NumberFormat().format(3500)
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat#basic_usage
You can use
out.toFixed(2).replace('.', ',');
This question already has answers here:
How can I get query string values in JavaScript?
(73 answers)
Closed 5 years ago.
Hey guys, I have this quite simple script which works great on chrome & firefox.
The idea is to nab "choice" value from the URL and proceed with the script. As mentioned other browsers work fine, but IE seems to have trouble with it.
Does anyone know a workaround? I don't want to just run the function on the previous page.
var url1 = "https://www.youtube.com";
var url2 = "http://ign.com";
function jukebox()
{
let params = (new URL(document.location)).searchParams;
let choice = params.get("choice");
if ( choice == 1 )
{
window.location=(url1);
}
else if ( choice == 2 )
{
window.location=(url2);
}
}
jukebox();
redirect();
IE does not support searchParams but you could try writing your own parse function:
var params = {};
var str = document.location;
var start = str.indexOf("?");
document.write(start+"<br>")
start += str.slice(start).indexOf("choice=") + 7;
var end = start + str.slice(start).indexOf("&") + 1;
if (!end) end = str.length
var choice = str.slice(start, end);
This question already has answers here:
How to use split?
(4 answers)
Closed 7 years ago.
I have a string like this 132+456 or 132-456 or 132*456..etc ,it changes dynamically but I need to split this into 132 and 456 how to do it using pure java script?
It should be as easy as:
var parts = '132+456'.split('+');
parts[0]; //132
parts[1]; //456
Like so
var data = '132+456'.split('+');
var a = data[0];
var b = data[1];
// document.writeln only for example
document.writeln(a);
document.writeln(b);
Java
String[] values='132+456'.split('+');
String firstPart=value[0]; // has 132
for js
var data = '132+456'.split('+');
var a = data[0];
var b = data[1];
This question already has answers here:
Is there a JavaScript function that can pad a string to get to a determined length?
(43 answers)
Closed 8 years ago.
I know this is a gimme, but I'm trying to make the filenames serialized with four digits instead of one. This function is for exporting PNG files from layers within Adobe Illustrator. Let me know if you ever need icons - much respect.
var n = document.layers.length;
hideAllLayers ();
for(var i=n-1, k=0; i>=0; i--, k++)
{
//hideAllLayers();
var layer = document.layers[i];
layer.visible = true;
var file = new File(folder.fsName + '/' +filename+ '-' + k +".png");
document.exportFile(file,ExportType.PNG24,options);
layer.visible = false;
}
Use util.printf (see the Acrobat API, page 720):
var file = new File(util.printf("%s/%s-%04d.png", folder.fsName, filename, k));
You can pad your number to the left and take the last four characters like this:
var i = 9;
var num = ("0000"+i);
var str = "filename"+(num.substring(num.length-4)); //filename0009
Or shorter
str = ("0000" + i).slice(-4)
Thanks to this question
This question already has answers here:
Wrong extraction of .attr("href") in IE7 vs all other browsers?
(7 answers)
Closed 8 years ago.
For example if
location.href = 'http://mydomain.com/en/'
and I have
i am just a link
so
href = $('a#id').attr('href');
for some reason Firefox, Chrome and Opera return: my-file.html
but IE7 will return: http://mydomain.com/en/my-file.html
I tried this function with the domain-name but gives an error:
function str_replace(busca, repla, orig)
{
str = new String(orig);
rExp = "/"+busca+"/g";
rExp = eval(rExp);
newS = String(repla);
str = new String(str.replace(rExp, newS));
return str;
}
domain-name is not defined
[Detener en este error] rExp = eval(rExp);
Any ideas for how to prevent it???
Try following :
//this will give you filename only
var chk = "http://mydomain.com/en/test.html";
var chkArr = chk.split("/");
var filenameOnly = chkArr.pop();
Hope it helps
You should avoid using eval in your code.
You can use str = str.replace(/.*\//, ''); to strip everything before the last / in a string.