Is there an easy way to modify this code so that the target URL opens in the SAME window?
<a href="javascript:q=(document.location.href);void(open('http://example.com/submit.php?url='+escape(q),'','resizable,location,menubar,toolbar,scrollbars,status'));">click here</a>``
To open a new tab, we have to use _blank in the second parameter of the window. open() method. The return value of window. open() is a reference to the newly created window or tab or null if it failed.
If you drag a tab out of an existing window and release it, it opens in its own window. Press "Ctrl-Shift-T" to open the last tab that you closed. Right-clicking on a link opens the page in a new tab. Alternatively, click on the link by pressing the center button or scroll wheel on your mouse.
In HTML, <a> tag is used to open URL on browser's window. The href attribute allows to add a hyperlink to the <a> tag and redirect one page to another. By default, the URL is opened in the same window. So, you don't need to define any attribute in <a> tag to open URL in the same tab or window.
<script type="text/javascript"> window.open ('YourNewPage.htm','_self',false) </script>
see reference: http://www.w3schools.com/jsref/met_win_open.asp
The second parameter of window.open() is a string representing the name of the target window.
Set it to: "_self".
<a href="javascript:q=(document.location.href);void(open('http://example.com/submit.php?url='+escape(q),'_self','resizable,location,menubar,toolbar,scrollbars,status'));">click here</a>
Sidenote: The following question gives an overview of an arguably better way to bind event handlers to HTML links.
What's the best way to replace links with js functions?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With