实现页面切换的话主要是使用到了h5新增的navigator属性。
操作:
PC页面=>PE页面
如果当前是pc端页面,加入以下代码,更改移动段代码,点击F12然后刷新页面即可进行切换。
if (/Android|webOS| iPhone | iPad | iPod |BlackBerry|opera mini|opera mobile|appleWebkit.*mobile|mobile/i.test(
navigator.userAgent)) {
window.location.replace("./mobile.html");
}
PE页面=>PC页面
同样在移动段要切会PC页面的话,只需要在前面加一个‘!’,并且更改pc页面路径即可。
if (!/Android|webOS| iPhone | iPad | iPod |BlackBerry|opera mini|opera mobile|appleWebkit.*mobile|mobile/i.test(
navigator.userAgent)) {
window.location.replace("./index.html");
}
当然如果说是要求极严的话,建议使用真机测试或手机模拟器测试。