Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript: open new page in same window

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>``
like image 861
55skidoo Avatar asked Nov 06 '08 05:11

55skidoo


People also ask

How do I open a new page in JavaScript?

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.

How do I open a tab in the same window?

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.

How do I make a link open in the same window?

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.


2 Answers

<script type="text/javascript"> window.open ('YourNewPage.htm','_self',false) </script> 

see reference: http://www.w3schools.com/jsref/met_win_open.asp

like image 189
parwaze Avatar answered Sep 19 '22 08:09

parwaze


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?

like image 27
keparo Avatar answered Sep 22 '22 08:09

keparo