Getting HEAD element from firefox plugin from overlay.js

I have a lightwiehgt plugin for firefox that needs to insert a script in HTML. The code is as follows:

var head = document.getElementsByTagName("head")[0];
var newscrpt;       
newscrpt = document.createElement('script');
newscrpt.type = "text/javascript" ;
newscrpt.src = "http://blabla.com/...";
newscrpt = head.appendChild(newscrpt);

The problem is that it document.getElementsByTagName("head")[0]returns 'undefined' and the check document.getElementsByTagName("head").lengthis 0.

It is currently being executed in the document.onLoad event of the browser, but I also tried calling it from window.setTimeoutto make sure that this is not a problem with loading synchronization, but the same thing happens.

Any ideas from anyone? Thank!

+3
source share
2 answers

frame iframe, document, - :

    var doc = frame.contentWindow.document;

. jQuery, :

    $(doc).find('head').append(
                '<link type="text/css" rel="stylesheet" href="MyStylesheet.css" />');

, .

0

Source: https://habr.com/ru/post/1725707/


All Articles