Open url in same tab AND 'document.write' after

有些话、适合烂在心里 提交于 2019-12-13 01:09:44

问题


Half of my question was answered with this.

I need to open another url (or replace location/href/src, whatever) in the current tab and after that inject HTML via document.write (or innerHTML, whatever) into the new page.

The code will be used in a Chrome bookmarklet which will open an enhanced version of the new page.

Here is what I got so far:

javascript: window.open('https://stackoverflow.com/','_self').document.write('Page Booster 3000');

Any thoughts are appreciated.

P.S 1: the code partially works if the url parameter is empty (''), but it remains in the old page domain.

P.S 2: any way of achieving this in plain vanilla JS?


回答1:


I've reading some threads and just found that it is neither a document.write issue nor a cross origin limitation.

I will take what gion_13 wrote in one of the reference threads:

"it won't work. new page = new script. can't run a script in a different page that it's declared in."

References:

Javascript bookmarklet go to URL and execute

Load a page and apply javascript in a single bookmark

tampermonkey script stops working if I change the page



来源:https://stackoverflow.com/questions/49523946/open-url-in-same-tab-and-document-write-after

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