Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Stay on Current page while using window.open

I am firing the Window.open(); command. which opens the link page in another tab. what i want is when i click the link, the link will open in new window but should be on the same page.

Is that possible ?

presently i am using like this.

function AddToDatabase(url) {
            window.open(url, "_blank");
}
like image 914
Moiz Avatar asked Mar 08 '13 17:03

Moiz


People also ask

Is it possible to open a new tab but stay on the current tab?

You can simply open a new tab and stay on the same page by: Right clicking the link that you want to open in a new tab. Then select, “Open link in new tab”

How do I open a link in a new tab but stay on the same page using HTML code?

How to Open Hyperlinks in a New Browser Tab or Window. The short answer is: just add a target="_blank" attribute to your links (anchor tags). Now when your visitors click that link, it will open in a new window or tab (depending on which web browser they are using and how they configured that browser).

How do I stay in the same page after clicking links?

usually href's ar used to transfer the request to another page.. If you want to redirect another page still the existing page remain open use target attribute.. If you dont want to redirect anywhere and still want send a signal while clicking the text, use onclick on the text and not the href.

How can you open a link in a new browser window?

To open a link in a new browser window, hold the Shift on then click the link or right-click the link and select Open link in New Window.


2 Answers

Use _self instead of _blank.

window.open(url, "_self");
  1. _blank - URL is loaded into a new window. This is default
  2. _parent - URL is loaded into the parent frame
  3. _self - URL replaces the current page
  4. _top - URL replaces any framesets that may be loaded name - The name of the window

For further details. See This Link

like image 100
Umair Saleem Avatar answered Nov 16 '22 21:11

Umair Saleem


The code you have should not be changing the page. How are you calling AddToDatabase()? Is it from an a href tag? If so the default action is taking place from the link and you need to prevent that.

You can set the href attribute to javascript:void(0)

<a href="javascript:void(0)" onclick="AddToDatabase('myUrl')">Add URL</a>

Or you can have the onclick attribute return false

<a href="#" onclick="AddToDatabase('myUrl'); return false;">Add URL</a>
like image 23
Rusty Jeans Avatar answered Nov 16 '22 23:11

Rusty Jeans