JS根据访问终端类型动态显示网页内容

//JS根据访问终端对应显示【iPhone|iPad|iPod|iOS】、【Android】、【PC】三种不同的内容

//主要原理为:JS根据id值修改对应HTML标签属性

<html>

<head>

<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />

<meta name="OS" content="width=device-width, initial-scale=1, maximum-scale=1"> 

<title></title>

<style type="text/css">

*{padding:0px;margin:0px;overflow:hidden;}

        body{background:#fff;}

.adbox{width:calc(100% - 5px);margin-left:5px;height:auto;overflow:hidden;padding-bottom:5px;}

.adbox a{float:left;width:48%;width:-webkit-calc(100% / 2 - 5px);width:-moz-calc(100% / 2 - 5px);margin-right:5px;margin-top:5px;background:#f00;position:relative;}

.adbox a img{display:block;width:100%;}

.adbox a 

</style>

</head>

<body>

<div class="adbox" id="adbox">

<div class="con">

 

<a id ="os_left"href='' target='_blank'><font color=black>点我吧←</font>

<img src="1.jpg"  alt="" />

</a>

<a id ="os_right"href='' target='_blank'><font color=black>→点我呀</font>

<img src="2.jpg" alt="" />

</a>

        </div>

</div>

 

<script type="text/javascript">

if(/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)){

document.getElementById("os_left").href="apple"; 

document.getElementById("os_right").hre ="apple"; 

} else if (/(Android)/i.test(navigator.userAgent)) {

document.getElementById("os_left").href="android"; 

document.getElementById("os_right").href="android"; 

} else {

document.getElementById("os_left").href="baidu"; 

document.getElementById("os_right").href="baidu"; 

}

</script>

</body>

</html>

文章来源:微笔记_博客

posted @ 2016-08-05 20:56  云产品解决方案  阅读(224)  评论(0编辑  收藏  举报