Spoof JS Objects

末鹿安然 提交于 2019-12-06 09:33:51

It is possible to spoof JS objects by replacing them. You will obviously have to be very careful that you don't mess up functionality that is required for desired operation. Anyway, here's an example of how the screen object can be replaced to report any resolution you want.

In action in a jsFiddle: http://jsfiddle.net/jfriend00/bfAYe/

var oldScreen = screen;  // save old screen object just in case

var myScreen = {};       // create new screen object

// prefill with all properties of old object
for (var i in screen) {
    myScreen[i] = screen[i];
}
screen = myScreen;    // replace existing object with mine
screen.width = 1440;  // change properites on mine
screen.height = 900;

// verify that changed properties are in place
$("#container").html("width="+screen.width+", height="+screen.height);

// outputs width=1440, height=900

Seems to work in Opera and Chrome, but not in IE9, FF5 or Safari. I guess you can't do this across browser.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!