8

I am very new to javascript, and written a program that will open a querystring as link.
I used window.open() , but the link is opening in new tab,
I want to open this link in the same tab.
The code is below.

var strquerystring;  
if(fromvalue==""||tovalue==""){  
  alert('kindly fill all the details');
}else{
  window.open(strquerystring);
}
taesu
  • 4,482
  • 4
  • 23
  • 41
user2897174
  • 81
  • 1
  • 1
  • 2

5 Answers5

14

You need to use the name attribute:

window.open("www.youraddress.com","_self");
ozil
  • 6,930
  • 9
  • 33
  • 56
8

Use

location.href = strquerystring;

Instead of window.open. It will then change the current URL.

progsource
  • 649
  • 7
  • 12
2

Use either of these:

// similar behavior as an HTTP redirect
window.location.replace("http://stackoverflow.com");

// similar behavior as clicking on a link
window.location.href = "http://stackoverflow.com";
taesu
  • 4,482
  • 4
  • 23
  • 41
1

Instead of asking the browser to open a new window. Try asking the browser to open a new location.

So in your else clause:

window.location = (window.location + strquerystring);

This will tell the browser to navigate to the location given. Instead of opening a new window. Thus keeping you in the same "tab"

Hope that helps.

MRUNAL MUNOT
  • 395
  • 1
  • 5
  • 18
Erik5388
  • 2,171
  • 2
  • 20
  • 29
0

If you want to change the current URL:

location.replace(strquerystring);
ioseph
  • 1,887
  • 20
  • 25