How can I embed a conditional comment for IE with innerHTML?
Posted
by
Samuel Charpentier
on Stack Overflow
See other posts from Stack Overflow
or by Samuel Charpentier
Published on 2012-09-23T20:13:41Z
Indexed on
2012/09/23
21:38 UTC
Read the original article
Hit count: 225
Ok so I want to conditionally add this line of code;
<!--[if ! IE]> <embed src="logo.svg" type="image/svg+xml" /> <![endif]-->
Using:
document.getElementById("logo") .innerHTML='...';
In a if()/else()
statement and it don't write it!
If i get rid of the selective comment ( <!--[if ! IE]><![endif]-->
) and only put the SVG ( <embed src="logo.svg" type="image/svg+xml" />
) it work! what should I do?
I found a way around but i think in the Android browser the thing will pop up twice.
here's what I've done ( and its Validated stuff!);
<!DOCTYPE html>
<html>
<head>
<META CHARSET="UTF-8">
<title>SVG Test</title>
<script type="text/javascript">
//<![CDATA[
onload=function()
{
var ua = navigator.userAgent.toLowerCase();
var isAndroid = ua.indexOf("android") > -1; //&& ua.indexOf("mobile");
if(isAndroid) {
document.getElementById("logo").innerHTML='<img src="fin_palais.png"/>';
}
}
//]]>
</script>
</head>
<body>
<div id="logo">
<!--[if lt IE 9]>
<img src="fin_palais.png"/>
<![endif]-->
<!--[if gte IE 9]><!-->
<embed src="fin_palais.svg" type="image/svg+xml" />
<!--<![endif]-->
</div>
</body>
© Stack Overflow or respective owner