Thursday, April 12, 2012

Chrome extension: how to dock extension's html page to current web page?

I want to develop a chrome extension which docks a new panel to the bottom of current web page. The GUI should be something like Firebug or Developer tools.


I tried to inject an iframe to web page like this:


$('body').append(
     '<iframe src="'
     + chrome.extension.getURL('panel.html')
     + '" style="position: fixed; width: 100%; bottom: 0px; height: 300px; display: block;"></iframe>');
 


The iframe can be seen, but it covers the content of the main page.
How can I solve the problem? Hope someone can give me some suggestions or simple examples...



Answer:

function windowLoaded() {
    alert('<html>' + document.documentElement.innerHTML + '</html>');
}
addEventListener("load", windowLoaded, false);
Notice how windowLoaded is created before it is used, not after, which won't work.
Also notice how I am getting the innerHTML of document.documentElement, which is the html tag, then adding the html source tags around it.

No comments:

Post a Comment