您的位置:首页 > 其它

使用history.length判断是否有上一页面,如果没有就返回到指定页面

2017-09-02 15:33 218 查看
使用history.length判断是否有上一页面,如果没有就返回到指定页面,一般是返回到首页

function goBack(){
if ((navigator.userAgent.indexOf('MSIE') >= 0) && (navigator.userAgent.indexOf('Opera') < 0)){ // IE
if(history.length > 0){
window.history.go( -1 );
}else{
window.location.href = "/";
}
}else{ //非IE浏览器
if (navigator.userAgent.indexOf('Firefox') >= 0 ||
navigator.userAgent.indexOf('Opera') >= 0 ||
navigator.userAgent.indexOf('Safari') >= 0 ||
navigator.userAgent.indexOf('Chrome') >= 0 ||
navigator.userAgent.indexOf('WebKit') >= 0){

if(window.history.length > 1){
window.history.go( -1 );
}else{
window.location.href = "/";
}
}else{ //未知的浏览器
window.history.go( -1 );
}
}
}

从这里想到一个用户的特殊需求,那就是在公众号中输入生日后 ,关闭H5,让公众号弹出二维码。当时说不可能,现在看来自己太年轻了。

window.opener=null;

window.close();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐