Reputation: 7591
I saw this little tip in Stack Overflow on how to get IE (in this case IE10, which does not support conditional HTML) to load a different JavaScript file.
Getting IE to load a different js file
However, in my case this hack is working for FireFox and IE, but not for Chrome. I suspect it is because my test is in the header. Is that True?
Should I be looking at something less declarative, and imperative like jquery getScript()?
(Chrome is not loading PouchDB-nightly.js)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Map DownLoader - V1.2</title>
<script src="../Kendo/jquery.1.9.1.min.js"></script>
<script src="../Kendo/kendo.all.js"></script>
<script src="xhr2lib.js"></script>
<script type="text/javascript">
var ie = !(navigator.userAgent.indexOf("MSIE") < 0);
if (ie == false) {
document.write("<script src=\"../PouchDB/pouchdb-nightly.js\"></scr" + "ipt>");
} else {
document.write("<script src=\"../PouchDB/pouchdb-nightly-IE.js\"></scr" + "ipt>");
}
</script>
<!-- <script src="../PouchDB/pouchdb-nightly.js"></script>-->
<script src="VM.js"></script>
<script src="LayerChooser.js"></script>
<script src="Downloader.js"></script>
<link href="../Kendo/styles/kendo.common.min.css" rel="stylesheet" />
<link href="../Kendo/styles/kendo.metroblack.min.css" rel="stylesheet" />
<link href="../Kendo/styles/kendo.dataviz.metroblack.min.css" rel="stylesheet" />
<link href="../Styles/ButtonStyles.css" rel="stylesheet" />
<link href="../Styles/DownloadStyle.css" rel="stylesheet" />
</head>
Upvotes: 0
Views: 1351
Reputation: 892
Try this, it works for me in chrome:
<script type="text/javascript">
function loadit(){
var head= document.getElementsByTagName('head')[0];
var script= document.createElement('script');
script.type= 'text/javascript';
script.src= '../PouchDB/pouchdb-nightly.js';
head.appendChild(script);
}
</script>
But probably you did some error because your code works in chrome to..
Upvotes: 1
Reputation: 14677
this should work in chrome and every other browser:
if (ie == false) {
var s = document.createElement('SCRIPT');
s.charset = 'UTF-8';
s.src ='../PouchDB/pouchdb-nightly.js';
document.getElementsByTagName('HEAD')[0].appendChild(s);
}
Upvotes: 0