How do I execute a page-defined JavaScript function from a Firefox extension?

前端 未结 5 1888
感动是毒
感动是毒 2021-01-04 21:14

I\'m creating a Firefox extension for demo purposes. I to call a specific JavaScript function in the document from the extension. I wrote this in my HTML document (not insid

5条回答
  •  悲&欢浪女
    2021-01-04 21:50

    I have a very simpler way to do it. Suppose you have to call xyz() function which is written on page. and you have to call it from your pluggin.

    create a button ("make it invisible. so it wont disturb your page"). on onclick of that button call this xyz() function.

    
    

    now in pluggin you have a document object for the page. suppose its mainDoc

    where you want to call xyz(), just execute this line

    mainDoc.getElementById('testbutton').click();
    

    it will call the xyz() function.

    good luck :)

提交回复
热议问题