How to add iframe with popup.html from script content

I want to add popup.html to web content. Below is my opinion

... page content <div> <--! injected content !--> <iframe src="chrome-extension:/21jk32j11k3kj11/popup.html"> </iframe> </div> 

Is it possible to show popup.html in web content?

+4
source share
1 answer

It is possible. When the version of manifest 2 is active (introduced in Chrome 18, required in Chrome 23), you must include the page in "web_accessible_resources" in the manifest file , though:

 { ... "web_accessible_resources": ["popup.html"], ... } 

The frame itself can be entered through the Content script , see the documentation for use and examples:

 // Within a content script: var f = document.createElement('iframe'); f.src = chrome.extension.getURL('popup.html'); document.body.appendChild(f); // Append to body, for example. 

chrome.extension.getURL returns the absolute URL of popup.html , for example chrome-extension://...32 letters.../popup.html .

+8
source

All Articles