移动端与PC端自动适配代码

写比较粗糙,勿怪

try {
	var test = window.location.pathname;//获取网址后面文件名
	var urlhash = window.location.hash;
	var locationurl = "http://m.网址.com";//移动端域名
	if (!urlhash.match("fromapp")) {
		if ((navigator.userAgent.match(/(iPhone|iPod|Android|ios|iPad)/i))) {
			window.location = locationurl + test;
		}
	}
}
catch (err) {
} 

知识共享许可协议
本作品采用知识共享署名-相同方式共享 4.0 国际许可协议进行许可。

你可能感兴趣的:(移动端与PC端自动适配代码)