Why does my Javascript return [object HTMLScriptElement] instead of expected text?
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:
Exception in thread "AWT-EventQueue-0" java.lang.NullPoint开发者_运维百科erException when trying to execute Javascript
Try 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
try hi.outerHTML and there is also an innerHTML, just saying so it may come handy someday
精彩评论