Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to change external script url onclick?
    text
    copied!<p>I have been struggling to find a solution for my issue. I'm not that of a experience person with javascript, but I am looking for a way to slighty change the external js url depending on an onclick event on an ahref.</p> <p>Right now I have this in my head tags:</p> <p><code>&lt;script type="text/javascript" src="http://www.domain.com/loader.php?GID=126&amp;go=&amp;sid="&gt;&lt;/script&gt;</code></p> <p>I want the SID parameter to be set to 1 or 2 based on an onclick on an anchor tag. The loader is called with this piece of code, but the SID would have to change right <strong>before</strong> the loader is being called.</p> <p><code>&lt;a href="/#download" onclick="javascript:Load_126(); return false;"&gt;</code></p> <p>Is there anyone that could tell me if it's possible? And maybe point me towards the right direction?</p> <p>Regards,</p> <p>Sedoc94</p> <p><strong>EDIT 1</strong>: I have been pointed in a direction and figured I could get this done with <code>jQuery.getScript()</code> But still have no clue how I should utilize it for my case.</p> <p><strong>EDIT 2</strong>: As the script need to be pulled from an external domain, I will have to go with the $.ajax() function.</p> <p>Right now I have:</p> <pre><code>function loadGame(sid){ $.ajax({ url: 'http://www.domain.com/loader.php?GID=126&amp;go=&amp;sid='+sid, dataType: "script", crossDomain: true, success: gLoad_12603() }); } </code></pre> <p>With an ahref onclick I'm calling the loadGame function, but the console says: <code>Uncaught ReferenceError: gLoad_12603 is not defined</code>. It should be working. But I'm guessing that it somehow gives this error because the function only exists in the script code that is returned from the external URL.</p> <p>Any ideas how I can make it work?</p>
 

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