简体   繁体   English

如何在页面加载chrome扩展名后调用javascript函数?

[英]How to call a javascript function after the page loads with a chrome extension?

There's a function on a page that I want to call after it loads. 页面上有一个函数,我想在加载后调用它。 I do not own the page, so I can't insert any html into it. 我不拥有该页面,因此我无法在其中插入任何html。 Can you please provide specific examples how to do this with some chrome extension or greasemonkey? 您能否提供一些具体示例,如何使用镀铬扩展或润滑脂? (function is submitAction() ). (函数是submitAction() )。

Both Chrome extensions and greasemonkey offer ways to specify when the script you inject if executed. Chrome扩展程序和greasemonkey都提供了指定执行时注入脚本的方法。

In Chrome extension, you set that in the manifest : 在Chrome扩展程序中, 您可以在清单中进行设置

"content_scripts": [
    {
        "run_at" : "document_idle",

In GreaseMonkey compatible userscripts, you set that in the metadata 在GreaseMonkey兼容的用户脚本中,您可以在元数据中设置它

// @run-at document-end

In both cases, you just have to add this to your script if you want to ensure resources are loaded when your function is executed : 在这两种情况下,如果要确保在执行函数时加载资源,则只需将其添加到脚本中:

document.addEventListener('load', submitAction);

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

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