I am having similar issues from
unable to run an external javascript using a bookmarklet .
But I am executing my JavaScript inside a Java application via injecting script headers into the current DOM loaded via Java application.
This problem seems to occur randomly. Some cases it returns [object HTMLScriptElement]
and other times returns the text...
When I alert()
the object, it returns text!
I have tried return String(hi);
but still no effect.
function returnsomeText(){
var hi = someArray.join(':');
alert(hi); //returns text:text:text:text as expected.
return hi; //returns [object HTMLScriptElement]
}
I am very confused to as what is causing this problem! If JavaScript returns [object HTMLScriptElement]
then my Java application cannot process the text.
This question is in more detail here:
尝试return hi.toString();
TRY adding .text somewhere like:
function returnsomeText(){
var hi = someArray.join(':');
alert(hi); //returns text:text:text:text as expected.
return hi.text;
}
HERE is a demo:
document.write(document.body.children[3]); //writes [object HTMLScriptElement]
document.write(document.body.children[3].text); //writes text data
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.