0

I'm trying to do a prompt which will lead me to another site but I want the other site to replace the current window I was in.

The code:

<button id="butt">press</button>

<script>
document.getElementById('butt').onclick = function()
{
var age = parseInt(prompt("please enter your age", "18")); //parseInt turns the string to numbers
   if(age >= 18)
   {
       window.open('http://www.walla.co.il','walla');
   }
 }  
Stephen Ostermiller
  • 23,933
  • 14
  • 88
  • 109
shay k
  • 163
  • 3
  • 13

3 Answers3

0

You can set new location.href.

window.location.href = 'http://www.walla.co.il'
Yury Tarabanko
  • 44,270
  • 9
  • 84
  • 98
0

you can use replace method:

document.getElementById('butt').onclick = function()
{
var age = parseInt(prompt("please enter your age", "18")); //parseInt turns the string to numbers
   if(age >= 18)
   {
       window.location.replace('http://www.walla.co.il','walla');
   }
}
Volkan Ulukut
  • 4,230
  • 1
  • 20
  • 38
0
window.open("http://www.walla.co.il","_self");

Above line opens the url in the same page.

Deepika
  • 331
  • 2
  • 7
  • 20
  • i tried that and it opens the window in the prompt. anyway people already told me the answer above but ty – shay k Jun 11 '14 at 10:52