0

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>
Community
  • 1
  • 1
Dr.YSG
  • 7,171
  • 22
  • 81
  • 139
  • There's nothing in your code which wouldn't work in Chrome. Probably you've something in the `pouchdb-nightly.js` which blocks the execution in Chrome. Any errors in the console? – Teemu Jun 24 '13 at 16:19
  • No errors in the console. But if I use the commented out line instead of the IF/ELSE code (i.e. forget about IE10 support, and only have FF and Chrome) then it works fine. Is there something about the fact that this script is running in the header that could affect things? – Dr.YSG Jun 25 '13 at 18:39
  • I don't get it, I've copied your code to a local file, and it works as it is. It just adds `` as expected in Chrome, FF and even Opera, while IE has a different filename in the path. It has to be something in the `pouchdb-nightly.js` itself. Anyway, maybe you should try the codes in below answers, they are supposed to be at least more modern to do the job. Though `head` is rather `document.head`. – Teemu Jun 25 '13 at 19:09
  • I am going to do a little testing (but it will have to wait till next week) on this. But since I have Jquery, what do you think of taking this entirely out of the header, and using jquery GetScript() after the page loads? – Dr.YSG Jun 27 '13 at 15:28

2 Answers2

1

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..

0

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);
  }
vendettamit
  • 14,315
  • 2
  • 32
  • 54