Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

window.open() should open the link in same tab

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);
}
like image 921
user2897174 Avatar asked Jan 27 '15 06:01

user2897174


4 Answers

You need to use the name attribute:

window.open("www.youraddress.com","_self");
like image 170
ozil Avatar answered Oct 25 '22 12:10

ozil


Use

location.href = strquerystring;

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

like image 33
progsource Avatar answered Oct 25 '22 12:10

progsource


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";
like image 30
taesu Avatar answered Oct 25 '22 12:10

taesu


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.

like image 20
Erik5388 Avatar answered Oct 25 '22 13:10

Erik5388