【发布时间】:2020-08-21 04:28:20
【问题描述】:
我使用此代码创建“a”元素以将其添加到页面。 (在第 3 方网站上,它是一个用户脚本)
let anchor = document.createElement("a");
anchor.href = new URL("https://duckduckgo.com");
console.log(anchor);
//anchor.target = "_blank";
//anchor.rel = "nofollow noopener noreferrer";
//anchor.click();
在控制台中运行此代码进行检查。
此代码在所有网站上都可以正常工作,web.archive.org 上的某些页面除外
例如:
在https://web.archive.org/web/19961220154510/https://www.yahoo.com/
我明白了
<a href="https://web.archive.org/web/19961220154510if_/https://duckduckgo.com/"></a>,
但应该<a href="https://duckduckgo.com/"></a>。
.click()(在上面)打开了这个错误的 URL。
如何解决?
Chrome 和 Firefox 都会出现这种情况。
UPD:window.open("https://duckduckgo.com") 也会出错。
它打开https://web.archive.org/web/20080820060021/http://duckduckgo.com/ 而不是https://duckduckgo.com/。
【问题讨论】:
标签: javascript google-chrome-extension userscripts