在同一个标​​签页中打开URL,然后在"document.write"

问题描述:

我的问题有一半被> .

我需要在当前选项卡中打开另一个URL(或替换location/href/src,随便什么),然后通过 document.write (或 innerHTML )注入HTML ,无论如何)进入新页面.

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.

该代码将在Chromebook小书签中使用,这将打开新页面的增强版本.

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: 如果url参数为空(''),则代码部分可用,但仍保留在旧页面域中.

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

P.S 2:以纯香草JS实现这一目标的任何方法?

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

我读了一些线程,只是发现它既不是 document.write 问题,也不是跨源限制.

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

我将采用 gion_13 在参考线程之一中写的内容:

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

"将不起作用.new page = new script.无法在 在其中声明的其他页面."

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

参考:

JavaScript小书签转到URL并执行

加载页面并在单个页面中应用javascript书签

如果更改页面,则tampermonkey脚本将停止工作