How to add JavaScript link dynamically?

Posted by Allemahesh under JavaScript on 1/6/2014 | Points: 10 | Views : 747 | Status : [Member] [MVP] | Replies : 1
I am using Mapquest Api in my web application. I am using this Mapquest Api in different pages. This api is given below:-

<script src="http://open.mapquestapi.com/sdk/js/v7.0.s/mqa.toolkit.js?key=YOURKEY"></script>

My question is How I can make key=YOURKEY dynamic. I mean to say that how to pass YOURKEY dynamical.

I have thought web.config file but I am not able to do this.
Can any one help me to sort this?




Responses

Posted by: kgovindarao523-21772 on: 1/6/2014 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Hi,
take a script tag like this.
<script type="text/javascript" id="myScript"></script>
Now in another script tag
define variable like
var src = "http://open.mapquestapi.com/sdk/js/v7.0.s/mqa.toolkit.js?key=";

and your dynamic varible is YOURKEY (may be passed it by click function)
and then dynamically assign src attibute to myScript
document.getElementById('myScript').src=src+YOURKEY;

Thank you,
Govind

Allemahesh, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response