Niraj
Niraj

Reputation: 157

How do I get a chrome extension to load an iframe containing a local page

I'm writing a chrome extension where the standard popup page is used as a menu and I add a iframe at the bottom of the page to display some output. the display.html page contains the output I intend to display in the iframe appended to the page. This code inside my content script appends the iframe but it searches for a display.html page on the webserver rather than in the code packaged with the extension. Is there some way for me to get it to load my display.html page rather than one that may or may not be there on whichever page the extension is used on.

ifrm = document.createElement("iframe");
ifrm.setAttribute("src", "display.html"); 
ifrm.style.width = "100%"; 
ifrm.style.height = "20%"; 
document.body.appendChild(ifrm); 

Upvotes: 3

Views: 2676

Answers (1)

Michael Aaron Safyan
Michael Aaron Safyan

Reputation: 95499

Updated answer

Per @Cnly's comment, please use chrome.runtime.getURL to get the URL of the embedded resource. (The original answer is extremely old, predating even manifest v2).

Original answer

I think you may want chrome.extension.getURL to get the URL of the embedded resource.

Upvotes: 2

Related Questions