Inject HTML into a page from a content script

后端 未结 5 1734
南旧
南旧 2020-11-28 23:35

I am building a Chrome Extension and I have a requirement to overlay a blob of html on top of a few websites. At the moment I am using a JQuery .Get to pull the

5条回答
  •  再見小時候
    2020-11-29 00:25

    This is my approach:

    var xmlHttp = null;
    
    xmlHttp = new XMLHttpRequest();
    xmlHttp.open( "GET", chrome.extension.getURL ("src/inject/inject.html"), false );
    xmlHttp.send( null );
    
    var inject  = document.createElement("div");
    inject.innerHTML = xmlHttp.responseText
    document.body.insertBefore (inject, document.body.firstChild);
    

    Without jQuery etc.

提交回复
热议问题