问题
i'm trying to create a safari extension and i'm stuck with something.
I have my global.html on my extension and i've been searching the web for like 3hours on how to retrieve the full html code without success.
I tried:document.getElementsByTagName('html')[0].innerHTML
(when i alert i only see the code that i have inside my global.html) document.documentElement.innerHTML
(nothing happens)
etc...
I used safari.application.activeBrowserWindow.activeTab.url
to retrieve the url but i cant get the html code.
Any help?
Thank you
回答1:
You can't get the HTML of a web page from your extension's global page. You have to use an injected script and then, if you want, you can pass the web page's HTML to your global page using safari.self.tab.dispatchMessage
. See this chapter in Apple's documentation.
来源:https://stackoverflow.com/questions/10322864/safari-extension-retrieve-full-html-code-from-a-page