在同一个标​​签页中打开URL,然后在"document.write" [英] Open url in same tab AND 'document.write' after

查看:130
本文介绍了在同一个标​​签页中打开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脚本将停止工作

这篇关于在同一个标​​签页中打开URL,然后在"document.write"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆