Simple Modal Wont Close | IE8 Bug | window.location.href

我是研究僧i 提交于 2020-01-06 06:49:36

问题


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

The code below...

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

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>

回答1:


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

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

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>


来源:https://stackoverflow.com/questions/20012180/simple-modal-wont-close-ie8-bug-window-location-href

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!