简单的模态Wont关闭| IE8错误| window.location.href [英] Simple Modal Wont Close | IE8 Bug | window.location.href

查看:98
本文介绍了简单的模态Wont关闭| IE8错误| window.location.href的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我早些时候发布了大约1个问题.已经解决了,但是又提出了另一个问题...

I posted earlier about 1 issue I was having. Got that fixed but it brought up another issue...

下面的代码...

在所有其他浏览器中单击是"时,将重新加载页面,而不会弹出SimpleModal.

When clicking "Yes" In every other browser The page will reload without SimpleModal coming back up.

但是在IE8中,它会持续加载SimplModal,从而拒绝访问该站点...

But in IE8 it continuously loads SimplModal thereby denying access to the site...

感谢您对高级人员的帮助!

Thanks for your help in advance guys!

 <!-- Init Age Verification Content -->

<div class="age" id="verify"> 
    <div><img src="white.png"></img></div>
    <div id="noman">ARE YOU OVER 18?</div>
    <div> 
      <p> If not, leave now and we wont tell your mom.
        </br>  By continuing you agree you're 18 or older.
      </p>
    </div>
    <div id="YN">
      <a href="javascript:window.location.href=window.location.href" id="old">Yes</a>
        &nbsp;&nbsp;&nbsp;&nbsp;
      <a href="example.com" rel="nofollow" id="young">No</a>
    </div>
</div>

<!-- If previous page wasn't from us... Verify -->

  <script>
if ( document.referrer == null || document.referrer.indexOf(window.location.hostname) < 0 ) {
$("#verify").modal({opacity:85, position: ["20%",""], onOpen: function (dialog) {
    dialog.overlay.fadeIn('slow', function () {
        dialog.container.slideDown('slow', function () {
            dialog.data.fadeIn('slow');
            return false;
        });
    });
}});
}
</script>

推荐答案

如果用户未通过链接导航到页面,IE不会设置document.referrer

IE doesn't set a document.referrer if the user didn't navegate to the page through a link

在MDN文档中:"如果用户使用,则该值为空字符串 直接导航到该页面(不是通过链接,而是,例如, 通过书签).由于此属性仅返回一个字符串,因此它确实 不允许您访问参考页面的DOM."

From the MDN documentation: "The value is an empty string if the user navigated to the page directly (not through a link, but, for example, via a bookmark). Since this property returns only a string, it does not give you DOM access to the referring page."

只需将链接的href更改为您页面的地址,或尝试此变通办法.

Simply change the link's href to your page's address or try this workaround.

<a href="javascript:redirect(window.location.href);" id="old">Yes</a>

<script type="text/javascript" >            
function redirect(url) {
    if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){
        var referLink = document.createElement('a');
        referLink.href = url;
        document.body.appendChild(referLink);
        referLink.click();
    } else {
        location.href = url;
    }
}
</script>

这篇关于简单的模态Wont关闭| IE8错误| window.location.href的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆