How to inject javascript into page, from a Firefox add-on, and run it?

后端 未结 2 415
予麋鹿
予麋鹿 2020-12-10 09:05

I\'m writing a Firefox extension (add-on) to allow users to annotate any page with text and/or drawings and then save an image of the page including the annotations. Use cas

相关标签:
2条回答
  • 2020-12-10 09:41

    Use the Greasemonkey extension :

    Allows you to customize the way a web page displays or behaves, by using small bits of JavaScript.

    Hundreds of scripts, for a wide variety of popular sites, are already available at http://userscripts.org.

    You can write your own scripts, too. Check out http://wiki.greasespot.net/ to get started.

    0 讨论(0)
  • 2020-12-10 09:42

    So this is how I solved my problem by setting the onload attribute to call the init function in the script that's being appended to the page.

    var myScript = top.window.content.document.createElement('script');
    myScript.type = 'text/javascript';
    myScript.setAttribute('src','chrome://path/to/script.js');
    myScript.setAttribute('onload', 'firefoxInit()');
    top.window.content.document.getElementsByTagName('head')[0].appendChild(myScript);
    
    0 讨论(0)
提交回复
热议问题