简体   繁体   中英

How can i get jQuery working in a tab created by my google chrome extension?

I create a tab from my background.html script in the extension, and it loads another .html file from the extension into the new tab. i'm trying to make use of some jQuery functions in this html file's script. Plain javascript works, but when I try to link jQuery, it simply doesn't work.

Do i have to use content scripts to obtain this functionality? And if so, am i able to call executeScript from background.html on the tab page?

Any suggestions are greatly appreciated. thanks

If jQuery is already included in the page, then you can use this skeleton in a userscript:

(function() {
    function topBar() {
        $(function() {
            /* your code here */
        });
    }

    var script = document.createElement("script");
    script.textContent = "(" + topBar.toString() + ")();";
    document.body.appendChild(script);
})();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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