gpt4 book ai didi

javascript - 将任意 JS URL 加载到 Chrome 中当前页面的上下文中?

转载 作者:行者123 更新时间:2023-12-02 19:51:06 26 4
gpt4 key购买 nike

在 Chrome 中,我有 jQuerify Chrome 扩展,它允许我将 jQuery 注入(inject)当前页面,以便我可以在控制台中使用 jQuery。

我想用其他任意 Javascript 来执行此操作。有没有办法在 Chrome 中本地执行此操作,例如类似于控制台中的 load("http://example.com/foo.js"); 。或者我需要编写扩展吗?

或者,如果另一个流行的浏览器可以本地执行此操作,那也很好。

最佳答案

我不相信他们有,但这是一句话:

document.documentElement.appendChild(document.createElement('script')).src = "http://example.com/foo.js";

...或者使用带有临时变量的三行版本,但这会变得更困惑:

var script = document.createElement('script');
script.src = "http://example.com/foo.js";
document.documentElement.appendChild(script);

关于javascript - 将任意 JS URL 加载到 Chrome 中当前页面的上下文中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9297551/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com