elseytd elseytd - 4 months ago 22x
Javascript Question

Javascript window.open() not working right?

I am trying to open a url in the same page when the user presses a button. But when I do this code on button press:

window.open("www.google.com", "_self");

It will open to this url:


Instead of just "www.google.com" ("MYSERVER" being where the html/js file is on).

How do I get it to be just "www.google.com" instead of "MYSERVER/www.google.com"?

Any help will be appreciated.


Change to:

 window.open("http://www.google.com", "_self");

With Javascript (unlike typing in the browser bar), you need to use a fully qualified URL or the JS will try to make it relative to the current page.