get innerHTML of the current tab ????

4,343 views
Skip to first unread message

BahCmoa

unread,
Nov 27, 2010, 7:04:56 PM11/27/10
to Chromium-extensions
Hi guys,
4 hours that i'm trying to do a "simple" thing without any result :
( ... all i would like is to be able to get the source code of a tab
(with "innerHTML") to write it in a hidden input of a form in a
background.html.

here is my code of background.html:
--------------------------------------------------------------------------------------------------------------------------
<script>
chrome.browserAction.onClicked.addListener(function(tab) {
var Inner = "JSvide";
chrome.tabs.executeScript(null, {code:" Inner =
document.body.innerHTML;"});

alert ("Inner : " + Inner) ;

document.getElementById("leCode").value =
Inner ;
document.getElementById("leForm").submit() ;
});
</script>
.
.
.
<form id="leForm" name="leForm" action="anotherPHPscript.php"
method="POST" target="_blank">
<input type="hidden" id="leCode" name="leCode" value="">
</form>
--------------------------------------------------------------------------------------------------------------------------

my problem is that i can get the "innerHTML" with
"chrome.tabs.executeScript" but after that, impossible to put it in
"Inner" ... then, impossible to write it in the form. When i launch
it, the "alert" shows me "JSvide" and not the HTML code of the
executeScript command.

If someone could have the beginning of a solution he/she would be God
for me !! :-)

thank you

Giovani Ceotto

unread,
Nov 30, 2010, 8:36:20 PM11/30/10
to BahCmoa, Chromium-extensions
Hi,
You might want to try using message passing right here: http://code.google.com/chrome/extensions/messaging.html. I am not an expert but I think that when you use the execute script API you are actually defining the 'Inner' variable only in the tabs and not in the background page. Please correct me if I`m wrong.


--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.
For more options, visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/?hl=en.




--
Giovani H Ceotto

PhistucK

unread,
Dec 1, 2010, 1:30:17 AM12/1/10
to Giovani Ceotto, BahCmoa, Chromium-extensions
Generally, you are correct, but even more so - the "Inner" variable exists only in the world of the content scripts of that tab, not in the world of that actual tab (the scripts from the host webpage itself cannot use "Inner"). Both of the worlds share the same DOM, but the global variables are separate.

PhistucK
Reply all
Reply to author
Forward
0 new messages