Question

Okay this is really getting to me now. My page does nothing when it's supposed to re-direct depending on a condition. The conditions are reached and I can print a message depending on a True or False result. But the re-directs simply aren't working. Everything I've looked at is telling me there's no reason why the codes not working but it simply isn't. I've tried on but Firefox and Chrome as well as getting a friend to try it on his PC. It simply hits a wall when it reaches the re-direction.

Here's my code:

<!DOCTYPE html>
<html>
<body>
    <p>Click the button to get a time-based greeting.</p>
    <button onclick="myFunction()">Try it</button>
    <p id="demo"></p>
    <script>
       function myFunction()
       {
         var x="";
         if(new Date("2014-03-04 21:00:00") < new Date())
         {
            x="GOOD";
         }
         else
         {
            window.location = "//www.google.com"
         }
         document.getElementById("demo").innerHTML=x;
      }
   </script>
</body>
</html>

I'd appreciate any help as I'm extremely new to HTML & Javascript. But could people please make sure there solution works at this link by copying there code into it and submitting it and obviously hitting the button.

No correct solution

OTHER TIPS

After reading your last comment, it sounds like you want the entire page to redirect, not just the iframe. So, you can force the parent window to change by replacing

window.location = "//google.com"

with

window.top.location = "//google.com"

Using top tells JavaScript to execute this on the parent. This works in JSFiddle, so it should work on your site as well.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top