Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'd suggest the answer to this question is using the "innerHTML" property of the DOM element. Certainly, if <em>the script has loaded</em>, you do <strong>not</strong> need to make an Ajax call to get it.</p> <p>So <a href="https://stackoverflow.com/questions/148441/how-can-i-get-the-content-of-the-file-specified-as-the-src-of-a-script-tag/151276#151276">Sugendran</a> should be correct (not sure why he was voted down without explanation).</p> <pre><code>var scriptContent = document.getElementById("myscript").innerHTML; </code></pre> <p>The innerHTML property of the script element should give you the scripts content as a string provided the script element is:</p> <ul> <li>an inline script, or</li> <li>that the script has loaded (if using the src attribute)</li> </ul> <p><a href="https://stackoverflow.com/questions/148441/how-can-i-get-the-content-of-the-file-specified-as-the-src-of-a-script-tag/148449#148449">olle</a> also gives the answer, but I think it got 'muddled' by his suggesting it needs to be loaded through ajax first, and i think he meant "inline" instead of between.</p> <blockquote> <p>if you where to have the js between and you could access it through innerHTML.</p> </blockquote> <hr> <p><strong>Regarding the usefulness of this technique:</strong> </p> <p>I've looked to use this technique for client side error logging (of javascript exceptions) after getting "undefined variables" which aren't contained within my own scripts (such as badly injected scripts from toolbars or extensions) - so I don't think it's such a way out idea.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload