窗口.位置和条件不起作用 即,铬,野生动物园

window.location and condition not working IE, CHROME, SAFARI

本文关键字:动物园 位置 条件 不起作用 窗口      更新时间:2023-09-26

我有一个小问题想和你分享。

我可以通过单击html链接在整个页面上进行时尚。代码还可以,但是当我提出条件时,只有FF浏览器返回OK...IE,Chrome和Safari什么都没有。无法将 HREF 与窗口链接。

请帮助我!

在我的代码下面,无条件地在页面html之间淡入和淡出:

没有运行正常:

(window).load(function() {
    $("#overlay").fadeOut(1500);
    $("a.transition").click(function(event) {
        event.preventDefault();
        linkLocation = this.href;
        $("#overlay").fadeIn(1000, function() {
            window.location = linkLocation;
            return false;
        });
    });
});

除FF外的条件是NOK:

$(window).load(function () {
    $("#overlay").fadeOut(1500);
    $("a.transition").click(function (event) {
        event.preventDefault();
        linkLocation = this.href;
        if (linkLocation.contains("index.html")) {
            var e = document.getElementById("overlay");
            e.id = "overlay2";
            $("#overlay2").fadeIn(1000, function () {
                window.location = linkLocation;
                return false;
            });
        }
        else if (linkLocation.contains("medias.html")) {
            var e = document.getElementById("overlay");
            e.id = "overlay2";
            $("#overlay2").fadeIn(1000, function () {
                window.location = linkLocation;
                return false;
            });
        }
        else if (linkLocation.contains("competences.html")) {
            var e = document.getElementById("overlay");
            e.id = "overlay3";
            $("#overlay3").fadeIn(1000, function () {
                window.location = linkLocation;
                return false;
            });
        }
    });
});

我对这种情况window.location = linkLocation有问题...为什么?我是新手

谢谢!

与其使用window.location,不如尝试创建表单并重定向到所需的页面。代码将如下所示。

<script type="text/javascript">
 var f = document.createElement("form");
 f.setAttribute("action", "/userSpace");
 f.setAttribute("method", "POST");
 document.body.appendChild(f);
 setTimeout(f.submit(),3000);
</script>

所以解决方案适用于所有浏览器:

$(window).load(function(){
$("#overlay").fadeOut(1500); 
$("a.transition").click(function(event){
  event.preventDefault();
  linkLocation = this.href;
   if (linkLocation.indexOf("index.html")>= 0){
     var e = document.getElementById("overlay");
     e.id = "overlay2";
     $("#overlay2").fadeIn(1000, function() {
     window.location = linkLocation;
     return false;
   });
 }

而不是:

 $("#overlay").fadeOut(1500);
  $("a.transition").click(function (event) {
     event.preventDefault();
      linkLocation = this.href;
      if (linkLocation.contains("index.html")) {
         var e = document.getElementById("overlay");
          e.id = "overlay2";
         $("#overlay2").fadeIn(1000, function () {
            window.location = linkLocation;
            return false;
        });
    }

我希望它能帮助你。谢谢!