用JS判斷IE版本的代碼 超管用!_javascript技巧

來源:互聯網
上載者:User
方法一:
複製代碼 代碼如下:

<script language="javascript">
function getIE()
{
if(navigator.appName == "Microsoft Internet Explorer")
{
if(navigator.appVersion.match(/7./i)=='7.')
{
//是IE7,不跳轉
}
else
{
//不是,跳轉
location.href='http://127.0.0.1';
}
}
}
</script>

方法二:
複製代碼 代碼如下:

<span id="Css"></span>
<script>
if(navigator.userAgent.indexOf("MSIE")>0)
{
//是否是IE瀏覽器
if(navigator.userAgent.indexOf("MSIE 6.0")>0)
{
//6.0 使用1.CSS
Css.innerHTML='<link href="1.css" rel="stylesheet" type="text/css" >'
}
if(navigator.userAgent.indexOf("MSIE 7.0")>0)
{
//7.0 使用2.CSS
Css.innerHTML='<link href="2.css" rel="stylesheet" type="text/css" >'
}
}else
{
//否則使用3.CSS 還有具體的瀏覽器 你可以用navigator.userAgent 去擷取資訊 具體使用 看你自己
Css.innerHTML='<link href="3.css" rel="stylesheet" type="text/css" >'
}
</script>

方法三:
複製代碼 代碼如下:

<html>
<head>
<link href="1.css" rel="stylesheet" type="text/css" id="MyCSS">
</head>
<body>
<script type="text/javascript">
function changeCss()
{
document.getElementById("MyCSS").href="2.css";
}
</script>
<div id="ts">test</div>
<input type="button" onclick="changeCss()" value="Change">
</body>
</html>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.