|
Answer» Hi there,
Just a question. A friend was telling me that he found some fetching code, in JS, that COULD detect what type of device and screen resolution a person is using. Once the device and resolution has been detected it will then display the web page to the resolution they are using on their device.
Is this JavaScript or is he getting confused with another language?
B2 Me again,
Any examples of this code would be great also!
B2 With a little help from Scriptomatic v2, I was able to tweak this into something you might find helpful:
Code: [Select]var wbemFlagReturnImmediately = 0x10; var wbemFlagForwardOnly = 0x20;
var objWMIService = GetObject("winmgmts:\\\\" + "." + "\\root\\CIMV2"); var colItems = objWMIService.ExecQuery("SELECT * FROM Win32_DesktopMonitor", "WQL", wbemFlagReturnImmediately | wbemFlagForwardOnly);
var enumItems = new Enumerator(colItems); var objItem = enumItems.item();
WScript.Echo("DisplayType: " + objItem.DisplayType); WScript.Echo("ScreenHeight: " + objItem.ScreenHeight); WScript.Echo("ScreenWidth: " + objItem.ScreenWidth);
Save SCRIPT with a JS extension and RUN from the command line as cscript scriptname.js
Quote Once the device and resolution has been detected it will then display the web page to the resolution they are using on their device.
Not sure how you plan to do this.
QuoteIs this JavaScript or is he getting confused with another language?
The above JScript uses the Windows Management Interface (WMI). Other LANGUAGES such as Powershell, Perl, Python, and VBscript all have the same access to the WMI classes. Even batch code can access the classes thru the WMIC command line utility (not available on XP Home).
Good luck.
Hi Sidewinder,
Thanks for the info and the example code! Will give it a GO but it also answers my question too.
thanks again!
B2
|