Reputation: 281
I am trying to load an external javascript file if the users viewing the page on ipad
but it doesn't matter what i do or where I put this code, it doesn't load the iPad.js
whatsoever when I view the page from my iPad 2 and it keeps loading the normal.js
file!
Here is the code:
<script language="javascript">
if (navigator.userAgent.match(/iPad/i) != null){ // may need changing?
var js = document.createElement('script');
js.type = "text/javascript";
js.src = "iPad.js";
var h = document.getElementById('closeHtml2')[0];
h.appendChild(js);
}
</script>
And this is how I get the normal.js on my page:
<script src="normal.js" type="text/javascript" charset="utf-8"></script>
could someone please help me out with this?
Upvotes: 0
Views: 431
Reputation: 318182
There is no getElementsByID
, it's getElementById
and it's not a nodeList, but a single element
if (navigator.userAgent.match(/iPad/i) != null){ // may need changing?
var js = document.createElement('script');
js.type = "text/javascript";
js.src = "iPad.js";
var h = document.getElementById('closeHtml2');
h.appendChild(js);
}
Upvotes: 1