I open and execute this function inside the opened browser via injected javascript (aka inappbrowser callbacks).
The function works because I see the alerts. The inappbrowser is opened via window.open(...):
var f_el_tname = document.body.getElementsByTagName("the_tag")[0];
//the above alerted "undefined" in android browser and the correct value in the desktop
//rewriting variable for debug purposes
f_el_tname = document.body.getElementsByTagName("the_tag");
alert(f_el_tname.length); //this gives "0" in phonegap android browser and "1" in desktop (correct)
for(var i = 0; i < f_el_tname.size; i++){
alert(f_el_tname); //this does not even run
}
Why exactly is this happening? With "desktop" and "android" I'm referring to accessing the phonegap instance in the desktop or in android, so the code and context are virtually the same. Any idea on why?
EDIT :
I think this might be happening because document in document.body.getElementsByTagName("the_tag");
is referring to the app document and not the document inside the inappbrowser. How can I get the document inside the browser inside the loadstop callback?
The windows is opened by var ref = window.open(...);
EDIT 2: as requested, here is the code
var ref = window.open(url,'_blank','location=yes,toolbar=no,hidden=yes','closebuttoncaption=Return');
ref.addEventListener('loadstop', function(){
var f_el_tname = ref.document.body.getElementById("l_fdb");
//the above gives an error
});
i < f_el_tname.size
->i < f_el_tname.length
?document
in the inappbrowser.executeScript context should mean the document inside the inappbrowser. – dasergeiab.executeScript
. I am only opening the callback and calling document directly in the callback function. Do I need to inject the script? And if so how can I get info from the new document to phonegap? – FaneI open and execute this function inside the opened browser via injected javascript (aka inappbrowser callbacks).
? See github.com/apache/cordova-plugin-inappbrowser/… for details on how to get results back from iab. – dasergeref.executeScript({code: code}, function(results){...});
? var code = '(function(){\n' + ' return document.body.getElementById("l_fdb");\n' + '})()'; – daserge