So I am trying to make a tab system for my website and I have been using window.open("The Website") except when I use it, the site opens on a new tab. Is there a way to make it open on the same tab?
3 Answers
If you assign to window.location, then the current window will load a new URL in that tab:
window.location = "http://www.yoursite.com";
See What's the difference between window.location and document.location in JavaScript? for why it is slightly safer (for cross browser compatibility) to use window.location instead of document.location, though in most browsers you can use either.
3 Comments
jfriend00
@StigCoder - I don't understand what you're asking. You assign a string URL to
window.location.leftclickben
@StigCoder No, you don't need the parentheses around the quotes.
window.open is a function, so you call it with parentheses - window.open(url). window.location is not a function, you assign a string to it with the = assignment operator as in the answer.var iframe = $('<iframe src="yoursite.com"></iframe>');
$(document).append(iframe);
1 Comment
leftclickben
Although technically, yes, this opens the site "in" (as in "somewhere within") the same tab, this is not the answer to the question. It's also not complete, you would need to at least set dimensions on that
iframe element.