龙空技术网

JavaScript:根据设备或浏览器更改位置或样式表

爱码农 87

前言:

此刻看官们对“js中修改css样式”大体比较看重,我们都需要分析一些“js中修改css样式”的相关内容。那么小编也在网络上汇集了一些有关“js中修改css样式””的相关资讯,希望姐妹们能喜欢,同学们一起来了解一下吧!

开发移动电话的web应用程序有时需要为不同的设备创建单独的内容。

不久前,我不得不创建一个网页应用程序,它看起来很漂亮,iPhone和一些基于Windows手机的HTC手机。最后,为WM设备创建另一个页面变得更加简单。

下面是我在web应用程序索引页的页眉中插入的一个代码片段:

<script type="text/javascript">function browser(){var browser = navigator.userAgent;//alert(browser);//Windows Mobileif (browser.match("MDA_compact")|| browser.match("MSIE")) {window.location.href = "mda/index.html";}//iPhone & Restelse{document.write('<meta name="apple-mobile-web-app-capable" content="yes" />'+'<link rel="apple-touch-icon" href="webapplogo.gif"/>' +'<meta name="apple-mobile-web-app-status-bar-style" content="black" />'+'<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />'+'<meta content="minimum-scale=1.0, width=device-width, maximum-scale=0.6667, user-scalable=no" name="viewport" />'+'<link href="style.css" rel="stylesheet" type="text/css" />'+'<link href="pie.css" rel="stylesheet" type="text/css" />'+'<link href="chart.css" rel="stylesheet" type="text/css" />'+'<link href="messages.css" rel="stylesheet" type="text/css" />'+'<link href="news.css" rel="stylesheet" type="text/css" />'+'<link rel="stylesheet" href="stylesheets/glider.css" type="text/css" media="screen" charset="utf-8">'); }}browser();</script>

您可能需要首先了解目标设备/浏览器是如何被调用的。取消对警告(浏览器)行进行注释并获取该名称。调整浏览器.match(“Target_browser”)并定义在这种情况下你想要做什么,例如重定向到另一个页面。

标签: #js中修改css样式 #js如何修改css样式 #js改变style #js添加样式表 #js设置位置