恶搞JS对象 [英] Spoof JS Objects

查看:431
本文介绍了恶搞JS对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在想,如果有一种方法欺骗像导航仪,屏幕等JS对象发送假数据,每当一个页面请求它。

I've been wondering if there is a way to spoof JS objects like navigator, screen, etc. to send fake data whenever a page request it.

我用C#开发,其中包含一个GeckoFx浏览器的应用程序,我想要做这样的事情:每一次我打开包含JS检索有关用户(信息例如屏幕分辨率的网页,有什么插件,我已经安装等),浏览器应该发送虚假信息(我的屏幕分辨率为1024x768,我想送1440等)。

I use C# to develop an application which contains a GeckoFx browser and I want to do something like this: every time I open a webpage which contains JS to retrieve information about the user (for example screen resolution, what plugins I have installed, etc), the browser should send fake information (my screen resolution is 1024x768 and I want to send 1440x900, etc).

谁能帮我这个资料片?

谢谢!

推荐答案

有可能取代他们欺骗JS对象。你会明显必须非常小心,你不要弄乱所需的所需操作的功能。总之,这里的的画面对象如何可以更换举报你想要的任何决议的例子。

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.

在在的jsfiddle行动: http://jsfiddle.net/jfriend00/bfAYe/

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

看起来对Opera和Chrome的工作,而不是在IE9,FF5或Safari。我猜你无法在浏览器中做到这一点。

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

这篇关于恶搞JS对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆