# Easy javascript thing not working

**URL:** <https://forum.kirupa.com/t/easy-javascript-thing-not-working/234747>\
**Category:** web dev\
**Created:** [August 5, 2007, 6:52pm UTC](https://forum.kirupa.com/t/easy-javascript-thing-not-working/234747 "2007-08-05T18:52:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mikken](https://avatars.discourse-cdn.com/v4/letter/m/e5b9ba/32.png) [@mikken](https://forum.kirupa.com/u/mikken)\
**Post date:** [August 5, 2007, 6:52pm UTC](https://forum.kirupa.com/t/easy-javascript-thing-not-working/234747/1 "2007-08-05T18:52:49Z")

</div>

Why isn’t this code working?

The browser won’t redirect to the new page, but the alert box shows, so i know that the conditional statement works.  
The location.href trick should also work, but here it doesn’t.

```auto
function confirm(num) {
  var r=confirm("Press a button")
  if (r==true)
    {
  alert(location.href);
   location.href="http://www.kirupa.com/"
    }
  else
    {
    document.write("You pressed Cancel!")
    }

}

```

And the strange thing is that if i paste it into [here](http://www.w3schools.com/js/tryit.asp?filename=tryjs_confirm) the code is working… What setting is wrong?
