Bookmarklet: Append hidden iframe to page and load

2019-02-07 05:16发布

I have a bookmarklet for resetting my router. I just need to visit and let the page finish loading, then my router starts resetting.

javascript:(function(){w=window.open("http://192.168.0.1/goform/formReboot","","width=1,height=1");self.focus();window.onload=w.close();})();

But it opens in a popup window.

My new idea is to dynamically append an hidden iframe to the page I'm on using a javascript bookmaklet, and then open the url in the hidden iframe. Is this even possible?

I'm open for better suggestion on how this can be done.

2条回答
该账号已被封号
2楼-- · 2019-02-07 05:34

Can it be done? Sure!

  1. Create an iframe element, with whatever parameters needed
  2. Add it as the last child to the body element
  3. Done!

Here's an example (everything would go on one line):

javascript:var%20ifra=document.createElement('iframe');
ifra.src="http://www.chron.com";
ifra.setAttribute("height","230");
ifra.setAttribute("width","360");
void(document.body.appendChild(ifra));
查看更多
我欲成王,谁敢阻挡
3楼-- · 2019-02-07 05:50

An even easier way would be to create a new IMG element:

(function(){
    (new Image()).src = "http://192.168.0.1/goform/formReboot";
})();

As a bookmarklet:

javascript:void((function(){(new Image()).src = "http://192.168.0.1/goform/formReboot";})());

Or, if that doesn't work, here's the 'iframe' creator you requested:

(function(){
    var i = document.createElement('iframe');
    i.style.display = 'none';
    i.onload = function() { i.parentNode.removeChild(i); };
    i.src = 'http://192.168.0.1/goform/formReboot';
    document.body.appendChild(i);
})();
查看更多
登录 后发表回答