Click here to Skip to main content
15,892,072 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
JavaScript
 <!--[if (gt IE 8)|(!IE)]>
<script src="/FileSaver.min.js"></script>
<script src="/underscroe.js"></script>
<![endif]--> 

I write the code like this and use firefox to debug it does not work,but When I write the codes directly,it works well.
JavaScript
<script src="/FileSaver.min.js"></script>
<script src="/underscroe.js"></script>
Posted
Comments
Prasad Khandekar 17-Jun-13 11:27am    
The conditional comments syntax is supported by IE only. For cross browser use javascript code something like shown below.

<script type="text/javascript">
_rwebkit = /(webkit)[ \/]([\w.]+)/;
_ropera = /(opera)(?:.*version)?[ \/]([\w.]+)/;
_rmsie = /(msie) ([\w.]+)/;
_rmozilla = /(mozilla)(?:.*? rv:([\w.]+))?/;

var brow = browserMatch(navigator.appVersion);
if (brow.browser !== 'msie' || (brow.browser === 'msie' && brow.version > 8)) {
var script = document.createElement("script");
script.setAttribute("src", 'FileSaver.min.js');
document.getElementsByTagName("head")[0].appendChild(script);

script = document.createElement("script");
script.setAttribute("src", 'underscroe.js');
document.getElementsByTagName("head")[0].appendChild(script);
}

// Taken from JQuery 1.7.1
function browserMatch(strUa) {
strUa = strUa.toLowerCase();
var match = _rwebkit.exec( strUa ) ||
_ropera.exec( strUa ) ||
_rmsie.exec( strUa ) ||
ua.indexOf("compatible") < 0 && _rmozilla.exec( strUa ) ||
[];

return { browser: match[1] || "", version: match[2] || "0" };
}
</script>
Zafar Sultan 17-Jun-13 11:58am    
Hi Prasad.
Sometimes there is a need to fix something such as css or appearance of certain elements when the browser is IE(for obvious reasons). The conditional comments are really useful as they are supported by IE only. Its kind of shortcut to execute commands only in case of IE. I think that was what the OP wanted to achieve. Anyways your solution is perfect for situations where a user want to perform cross browser tasks. You should have posted it as a solution. I wish I could give a +5 for that.

1 solution

Try this:

HTML
<!--[if gt IE 8]><!-->
Load your scripts here. But first make sure this message is displayed if your browser is IE8 or not IE
<!--<![endif]--> 


Also keep in mind, according to Microsoft Document[^] these statements will not work in IE10
 
Share this answer
 
v2
Comments
PEIYANGXINQU 17-Jun-13 13:15pm    
Thank you, when user use IE10 to view my web,you say these statements will not work ,but in fact in IE10 my scripts also work,I think because of '<!-->'.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900