开发者

Invoking original unmolested window.open from bookmarklet

开发者 https://www.devze.com 2023-02-19 03:38 出处:网络
I have general purpose bookmarklet, which begins with: javascript:with (window.open(\"\")) {/* lots of irrelevant characters */

I have general purpose bookmarklet, which begins with:

javascript:with (window.open("")) {/* lots of irrelevant characters */

It works as should (opens new window and writes a report about page elements, specifically), however fails on certain pages, when authors decide what open is a good name for function:

/* somewhere in global scope */
function open() { /* something */ }

... effectively replacing window.open and breaking bookmarklet operation. By the nature of bookmarklet i cannot do anything to prevent such misbehaviour.

Is there any way to call original native window.open to recover in this 开发者_如何学运维cases? Please note, my primary browser is Opera, i really want to make it work in there.


window.constructor.prototype.open

Nope, sorry. You can do some hackery to get a new one though :)

var ifr = document.createElement('iframe');
document.body.appendChild(ifr);
ifr.contentWindow.open(...)

0

精彩评论

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