javascript - 简单模态不会关闭 | IE8 错误 |窗口位置.href

标签 javascript jquery internet-explorer simplemodal

我之前发布了关于我遇到的 1 个问题。解决了这个问题,但又带来了另一个问题......

下面的代码...

当在所有其他浏览器中单击"is"时,页面将重新加载,而 SimpleModal 不会恢复。

但在 IE8 中,它会不断加载 SimplModal,从而拒绝访问该网站...

感谢你们提前提供的帮助!

 <!-- 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

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 更改为您的页面地址或尝试此解决方法即可。

<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>

关于javascript - 简单模态不会关闭 | IE8 错误 |窗口位置.href,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20012180/

相关文章:

javascript - 删除使用 jQuery 动态创建的元素

javascript - Webpack 监视文件更改并触发其他文件的加载程序

javascript - 加载后更改 data-progress-text 中的文本

php - IE8 中页面未完全加载(html 源代码被截断)

javascript - Flexslider 在 IE9 中不工作

javascript - 使用花括号在 Internet Explorer 上的 AngularJS 数据绑定(bind)问题

javascript - 是否可以绕过内置 JavaScript 函数

javascript - 在这种情况下如何切换动画?

php - 如何在php循环中显示隐藏的数据类型?

javascript - 强制同步 XMLHttpRequest/Ajax 而不发出警告