Hi people, the following code is not working for IExplorer. Could you help me? <script id=url language=javascript ></script> <script type="text/javascript">document.getElementById("url").src = "http://localhost/aro.aspx?&key=C763&refnum=yY9&location=" + document.location;</script>
I suggest that if you want to load javascript files on the flow to use jquery http://api.jquery.com/jQuery.getScript/
Some browsers don't work with document.getElementById. This is universal function for all browsers: function getElement(id) { var itm = null; if (document.getElementById) { itm = document.getElementById(id); } else if (document.all){ itm = document.all[id]; } else if (document.layers){ itm = document.layers[id]; } return itm; } var node = getElement("url") if (node) { node.src = ... } Code (markup):
try checking if you can actually access the script like this: var e = document.getElementById("url"); alert(e); if the alert gives you a script object, then you're fine. if it's undefined, you know this won't work.
google 'lazyloading javascript'. what you are doing is correct - have a look at http://ajaxpatterns.org/On-Demand_Javascript the favoured lazyload method is <script> document.write('<script src="', 'http://cross.domain.com/other.js', '" type="text/javascript"><\/script>'); </script> Code (javascript): - most compatible and non-blocking, i suppose.