Simple Modal Wont Close | IE8 Bug | [removed].href

2019-08-24 18:09发布

问题:

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>