简体   繁体   English

Chrome扩展程序:通过多个页面运行Javascript?

[英]Chrome Extension: Running Javascript Through Multiple Pages?

I am working on a google chrome extension that runs javascript when a particular site is accessed (ie images.myDomain.com/ ). 我正在研究访问特定网站(例如images.myDomain.com/ 时运行javascript的google chrome扩展程序 Once the javascript is injected, it then triggers a button click to go to a new page (ie frames.myDomain.com/ ). 一旦注入了javascript,它就会触发按钮单击以转到新页面(即frames.myDomain.com/ )。 The problem is once this new page loads, I want to continue running more javascript, but I know I can't. 问题是一旦加载了新页面,我想继续运行更多的javascript,但我知道不能。

Should I build 2 separate extensions? 我应该建立2个单独的扩展程序吗? One that reacts to images.myDomain.com and another that reacts to frames.myDomain.com, or is there a simple way of doing this with one extension? 一个对images.myDomain.com做出反应,另一个对frames.myDomain.com做出反应,或者是否有一种简单的方法通过一个扩展名来做到这一点? Like maybe having two separate js files? 好像有两个单独的js文件?

Any help is appreciated thanks! 任何帮助表示赞赏,谢谢!

You can use multiple content_script declarations in your manifest file. 您可以在清单文件中使用多个content_script声明。 Something like this: 像这样:

"content_scripts": [
    {"matches": ["http://images.myDomain.com/*"], "js": ["some_script.js"]},
    {"matches": ["http://frames.myDomain.com/*"], "js": ["some_other_script.js"]}
],

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM