使用history.length判断是否有上一页面,如果没有就返回到指定页面
2017-09-02 15:33
218 查看
使用history.length判断是否有上一页面,如果没有就返回到指定页面,一般是返回到首页
从这里想到一个用户的特殊需求,那就是在公众号中输入生日后 ,关闭H5,让公众号弹出二维码。当时说不可能,现在看来自己太年轻了。
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();
相关文章推荐
- mysql中的判断是否有该条数据 如果有返回1 没有返回0
- 检查子窗体中是否已经含有指定类型的窗体,如果有,则激活,如果没有则返回false!
- 判断一个单链表是否有环。如果有,把指向环开始的指针返回;如果没有,返回NULL。
- 判断是否有网络,如果没有网络,弹出对话框,然后可以跳转到设置页面
- web 开发,个人中心每个请求,判断用户是否登录,若没有登录,则跳转到登录页面,登录成功后返回之前页面
- 使用JS来判断页面中的链接是否有效
- 如何在JS中判断页面上是否存在指定控件
- js如果判断select是否选中或选中指定项
- 回发或回调参数无效。在配置中使用 或在页面中使用 启用了事件验证。出于安全目的,此功能验证回发或回调事件的参数是否来源于最初呈现这些事件的服务器控件。如果数据有效并且是预期的,则使用 ClientScriptManager.RegisterForEventValidation 方法来注册回发或回调数据以进行验证。
- 丶使用is关键字判断对象是否与指定类型兼容
- 判断一个字符串是否是回文,如果是,返回字符串“yes”,如果不是,返回字符串“no”
- 用js实现判断当前网址的来路如果不是指定的来路就跳转到指定页面
- 分割字符串到数组/替换字符串/返回指定字节长度的字符串/判断是否为浮点数,包括double和float/email判断/是否纯汉字判断/空白判断
- js判断指定的页面是否有效存在
- 回发或回调参数无效。在配置中使用 或在页面中使用 启用了事件验证。出于安全目的,此功能验证回发或回调事件的参数是否来源于最初呈现这些事件的服务器控件。如果数据有效并且是预期的,则使用 ClientSc
- 回发或回调参数无效。在配置中使用 或在页面中使用 启用了事件验证。出于安全目的,此功能验证回发或回调事件的参数是否来源于最初呈现这些事件的服务器控件。如果数据有效并且是预期的,则使用 ClientScriptManager.RegisterForEventValidation 方法来注册回发或回调数据以进行验证。
- 回发或回调参数无效。在配置中使用 或在页面中使用 启用了事件验证。出于安全目的,此功能验证回发或回调事件的参数是否来源于最初呈现这些事件的服务器控件。如果数据有效并且是预期的,则使用 ClientScriptManager.RegisterF
- JS判断用户是否有权限进入当前页面,没有直接关闭(解决IE7以上版本提示问题)
- 回发或回调参数无效。在配置中使用 或在页面中使用 启用了事件验证。出于安全目的,此功能验证回发或回调事件的参数是否来源于最初呈现这些事件的服务器控件。如果数据有效并且是预期的,则使用 ClientScriptManager.RegisterForEvent
- sql server中列中字符换使用分割字符后,判断是否存在指定的项