【问题标题】:Simple Modal Wont Close | IE8 Bug | window.location.href简单模态不会关闭 | IE8 错误 | window.location.href
【发布时间】:2013-11-15 23:04:38
【问题描述】:

我早些时候发布了关于我遇到的 1 个问题。解决了这个问题,但它带来了另一个问题......

下面的代码...

当在所有其他浏览器中单击“是”时,页面将重新加载,而不会重新启动 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>

【问题讨论】:

  • 首先验证哪些是意外的:document.referrer window.location.hostname
  • 感谢您的快速回复 :) 您能说得更具体一点吗?我绝不是编码员。谢谢!
  • 在IE8(或更高版本的IE并选择IE8/8作为模型)中打开IE开发工具(按F12)。然后,在不应该显示模式对话框的页面上,在控制台上输入document.referrer(和window.location.href)并观察值。请参阅msdn.microsoft.com/en-us/library/dd565628(v=vs.85).aspx(用于 IE8)或msdn.microsoft.com/en-us/library/gg589507(v=vs.85).aspx(用于“F12”)。我怀疑 document.referrer 在这种情况下是“不正确”的值。
  • document.referrer 功能不可靠,您根本不应该使用它。
  • 我不知道有任何其他方法可以让一个人在任何页面上通过如果它是第一次在网站上进行年龄验证,如果他们点击确定将他们发送到他们请求的页面。我无法将链接更改为 url,因为它们可能来自不同的页面。一旦我弄清楚如何实现它,我将立即尝试下面的答案lol

标签: javascript jquery internet-explorer simplemodal


【解决方案1】:

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

来自 MDN 文档:“如果用户 直接导航到页面(不是通过链接,而是,例如, 通过书签)。由于这个属性只返回一个字符串,它确实 不授予您对引用页面的 DOM 访问权限。"

只需将链接的 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>

【讨论】:

  • 我完全不知道这是如何工作的,但它确实有效。 :) 我在当前脚本之后添加了这个脚本,所有问题都解决了。谢谢大佬!
猜你喜欢
  • 2014-08-09
  • 2012-01-06
  • 1970-01-01
  • 1970-01-01
  • 2018-12-18
  • 1970-01-01
  • 2020-09-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多