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

痞子三分冷 提交于 2019-12-10 20:56:48

问题


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);
}

回答1:


Use

location.href = strquerystring;

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




回答2:


You need to use the name attribute:

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



回答3:


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";



回答4:


If you want to change the current URL:

location.replace(strquerystring);



回答5:


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.



来源:https://stackoverflow.com/questions/28164479/window-open-should-open-the-link-in-same-tab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!