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.NullPointerException when trying to execute Javascript
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.NullPointerException when trying to execute Javascript
Share Improve this question edited May 23, 2017 at 12:00 CommunityBot 11 silver badge asked Jan 18, 2011 at 9:47 KJWKJW 15.3k51 gold badges141 silver badges247 bronze badges 9-
2
What is
someArray
? How can you tell it's returning[object HTMLScriptElement]
? – user447356 Commented Jan 18, 2011 at 9:49 -
if all else fails I guess you could try
''+hi
to force it to be a string. that doesn't actually answer the question though. – Spudley Commented Jan 18, 2011 at 9:52 -
@Spudley:
[object HTLMScriptElement]
is the result of coercing a<script>
element to a string anyway, so the result will not change. The problem isn't with the code here, it's wherereturnsomeText()
is being called that's likely the issue. We need to see more code. – Andy E Commented Jan 18, 2011 at 9:57 - Hi Kim, Can you return hi.ToString();? – WraithNath Commented Jan 18, 2011 at 9:57
- @Kim, glad to here it, ill undelete my Answer! – WraithNath Commented Jan 18, 2011 at 10:12
3 Answers
Reset to default 6Try 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 e handy someday