admin管理员组文章数量:1356294
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
本文标签: javaWhy does my Javascript return object HTMLScriptElement instead of expected textStack Overflow
版权声明:本文标题:java - Why does my Javascript return [object HTMLScriptElement] instead of expected text? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743977751a2570945.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论