Laurent Poulet
Laurent Poulet

Reputation: 49

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

I have a little problem that I would share with you.

I can do a fadout fadin on a whole page by clicking html links. The code is ok BUT when i put the condition only FF browser return OK... IE, Chrome and Safari nothing. Impossible to link HREF with window.location...

Please help me !

Below my code to fadeIn and fadeOut between pages html without condition and with :

Without running ok :

(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;
        });
    });
});

With condition NOK except FF :

$(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;
            });
        }
    });
});

I have trouble with window.location = linkLocation for the condition... Why ? I'm novice

Thanks !

Upvotes: 1

Views: 201

Answers (2)

Laurent Poulet
Laurent Poulet

Reputation: 49

So the solution is for all the browsers :

$(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;
   });
 }

instead of :

 $("#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;
        });
    }

I hope it can help you. Thanks !

Upvotes: 0

Sumodh S
Sumodh S

Reputation: 741

Rather than using window.location try to create form and redirect to the page you wanted. The code will look something like this.

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

Upvotes: 1

Related Questions