开发者

Can js code on a site prevent other js code from detecting presence of flash?

I'm looking for 开发者_运维百科a workaround to the "AdSense does not let you choose only images but no flash" issue. I'm rather a newbie to JS, but is there any way for one script to prevent other scripts embedded in a site from detecting the presence of the flash plugin? Even if it doesn't work with AdSense, it would be nice to know if there's a hack to do this that might work in other settings.

By the way, I suppose I wouldn't care if it failed to work on IE or obsolete browser versions.


It looks like adsense detects flash by looking at the content of navigator.plugins["Shockwave Flash"]. Unfortunately, you can't just set just that to a different value, as browsers won't let you. Similarly, you can't set navigator.plugins. Some browsers let you delete navigator.plugins, but not all of them.

However, you can set navigator. So the path to do what you want involves creating a fake navigator object.

var real_navigator = navigator;
navigator = { plugins:[], mimeTypes:[] };
for (var k in real_navigator) {
  var t = typeof real_navigator[k];
  if (t == "string" || t == "function") {
    navigator[k] = real_navigator[k];
  }
}

At that point, you can still have scripts that inspect your user-agent and such, but plugins and mimetypes won't show up.

It's not fool-proof, and you'd have to stub ActiveXObject if you want IE to play along, but overall, this should get you closer to your goal.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜