Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I guess you should be able to do the following:</p> <pre><code>javascript:(function () { var newScript = document.createElement('script'); newScript.type = 'text/javascript'; newScript.src = 'http://depot.com/file.js'; document.getElementsByTagName('body')[0].appendChild(newScript); })(); </code></pre> <p>Here's a very useful example (paste this in your address bar):</p> <pre><code>javascript:(function () { var newScript = document.createElement('script'); newScript.type = 'text/javascript'; newScript.src = 'http://cornify.com/js/cornify.js'; document.getElementsByTagName('body')[0].appendChild(newScript); for (var i = 0; i &lt; 5; i++) { newScript = document.createElement('script'); newScript.type = 'text/javascript'; newScript.src = 'http://cornify.com/js/cornify_run.js'; document.getElementsByTagName('body')[0].appendChild(newScript); } })(); </code></pre> <p>Voila:</p> <p><img src="https://i.stack.imgur.com/jB9hA.jpg" alt="Stack Overflow cornified"></p> <p>In fact, this is how <a href="http://www.cornify.com/" rel="nofollow noreferrer">cornify.com</a> is including the remote scripts in their bookmarklet.</p> <hr> <p><strong>UPDATE:</strong></p> <p>As <a href="https://stackoverflow.com/questions/3742118/load-remote-javascript-files-via-address-bar/3742363#3742363">@Ben noted in the other answer</a>, it's not that straightforward to call a function defined in your remote script. Ben suggests one solution to this problem, but there is also another solution, the one that cornify are using. If you check out <code>http://cornify.com/js/cornify_run.js</code> you'll see that there's just one function call in that file. You could place your <code>funcname()</code> call in a separate JavaScript file, as cornify are doing, because script blocks are guaranteed to be executed in the order they are inserted. Then you'd have to include both scripts, as in the following example:</p> <pre><code>javascript:(function () { var newScript = document.createElement('script'); newScript.type = 'text/javascript'; newScript.src = 'http://depot.com/file.js'; document.getElementsByTagName('body')[0].appendChild(newScript); newScript = document.createElement('script'); newScript.type = 'text/javascript'; newScript.src = 'http://depot.com/file_run.js'; document.getElementsByTagName('body')[0].appendChild(newScript); })(); </code></pre> <p>Where the <code>file_run.js</code> simply includes a call to <code>funcname()</code>.</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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. 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