数码资讯
JS判断网页关闭网页时不背或history.go(-1)
选购提示
关注价格、性能、续航、售后和真实使用场景,理性比较后再下单。
当制作一个Web项目时,有一个需求。当页面没有前兆的历史,它是不可能去操作,即history.go(- 1),然后关闭页面,直接点击返回按钮,否则,它将返回到上一页。
遇到的问题是如何确定历史是否可以退货,这是很麻烦的,因为有这样的直接访问处理功能没有,只有通过history.length变做工作,但对IE浏览器,IE和非长度返回值是不同的,即:历史。长度= 0,即是1,所以写一个函数来实现上述要求的功能,分享给你。
*返回到上一页(或关闭此页)
*如果没有上一页历史记录,则当前页直接关闭。
* /
函数返回(){
如果((navigator.useragent.indexof('msie ')> = 0)(navigator.useragent.indexof('opera)<0)){ / /伊江
如果(history.length > 0){
Window.history.go(1);
其他{ }
窗口。开瓶器= null;window.close();
}
}其他IE浏览器
如果(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){
如果(window.history.length > 1){
Window.history.go(1);
其他{ }
窗口。开瓶器= null;window.close();
}
}其他未知浏览器
Window.history.go(1);
}
}
}
遇到的问题是如何确定历史是否可以退货,这是很麻烦的,因为有这样的直接访问处理功能没有,只有通过history.length变做工作,但对IE浏览器,IE和非长度返回值是不同的,即:历史。长度= 0,即是1,所以写一个函数来实现上述要求的功能,分享给你。
*返回到上一页(或关闭此页)
*如果没有上一页历史记录,则当前页直接关闭。
* /
函数返回(){
如果((navigator.useragent.indexof('msie ')> = 0)(navigator.useragent.indexof('opera)<0)){ / /伊江
如果(history.length > 0){
Window.history.go(1);
其他{ }
窗口。开瓶器= null;window.close();
}
}其他IE浏览器
如果(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){
如果(window.history.length > 1){
Window.history.go(1);
其他{ }
窗口。开瓶器= null;window.close();
}
}其他未知浏览器
Window.history.go(1);
}
}
}
声明:本文内容用于数码产品信息整理与选购参考,具体价格、库存、售后政策以官方渠道和电商页面实时信息为准。