Why does my Javascript return [object HTMLScriptElement] instead of expected text?
<p>I am having similar issues from</p>

<p><a href="http://stackoverflow.com/questions/2222417/unable-to-run-an-external-javascript-using-a-bookmarklet">unable to run an external javascript using a bookmarklet</a>.</p>

<p>But I am executing my JavaScript inside a Java application via injecting script headers into the current DOM loaded via Java application.</p>

<p>This problem seems to occur randomly. Some cases it returns <code>[object HTMLScriptElement]</code> and other times returns the text...</p>

<p>When I <code>alert()</code> the object, it returns text! </p>

<p>I have tried <code>return String(hi);</code> but still no effect.</p>

<pre><code>function returnsomeText(){
    var hi = someArray.join(':');
    alert(hi); //returns text:text:text:text as expected.
    return hi; //returns [object HTMLScriptElement]
}
</code></pre>

<p>I am very confused to as what is causing this problem! If JavaScript returns <code>[object HTMLScriptElement]</code> then my Java application cannot process the text.</p>

<p>This question is in more detail here:</p>

<p><a href="http://stackoverflow.com/questions/4732618/exception-in-thread-awt-eventqueue-0-java-lang-nullpointerexception-when-trying">Exception in thread &quot;AWT-EventQueue-0&quot; java.lang.NullPointerException when trying to execute Javascript</a></p>
