How do I change an url in the template file dynamically

Get help using Construct 2

Post » Wed Apr 16, 2014 10:41 am


The case I am trying to crack is the following. We are implementing a change on our website to host all content in the amazon cdn cloud. This means the url (src="c2runtime.js") of the c2runtime.js must change. Changing the url in the template is easy if it would need to point to one location. But in this case we host multiple games on our portal. And I would like to find a sollution that would prevent me from having to change the url manually each time I export.

The src in the html template would look something like this (i'm trying to set GAMENAME dynamically):
<script src="'+ GAMENAME +'/c2runtime.js"></script>

So far I have tried finding a way to change the script's src by making it a variable and constructing the link through

<script type="text/javascript">
var myURL = '//'+ document.title +'/c2runtime.js';
document.getElementById('runtimeURL').src = myURL;
<script id="runtimeUrl" src=""></script>

But this gets me nowhere. It doesnt set the src.

I also tried to set it using jQuery through the following:

$(document).ready(function() {
$('script#runtimeUrl').attr('src', '//'+ document.title +'/c2runtime.js');

But the page needs c2runtime.js before this is run apparently.

Does anyone have any tips on how I can set the reference to c2runtime.js dynamically?

Any help is greatly appreciated. If there is information you need that i forgot to include please let me know. Thanks in advance.
Posts: 6
Reputation: 287

Return to How do I....?

Who is online

Users browsing this forum: SuperSciFi and 6 guests