How can I open a link in new tab? - javascript

I have got a task to open the link in a new tab.For that I tried the below code
window.open($(this).attr("data-MenuLink"), 'target=_new');
and also window.open($(this).attr("data-MenuLink"), 'target=_blank');
But the problem is that when I click on the first time, it will load on new tab and work properly. But on second time it will just reload on the previously created tab, rather than new one. I need to open the window in new tab on each click

CSS3 supports "open in new tab", by the property
target-new: window | tab | none;
See this
Otherwise, you can use the browser properties to force windows to open in a new tab.
EDIT: It does not seem to be supported by any browser currently. This seems to work in firefox
content of the anchor
Else, use this method to resize window immediately, to ensure that popup blockers do not kill your popup

Hi Try This code,
content of the anchor

window.open('www.yourdomain.com','_blank');

window.open('http://www.yahoo.com','_blank','width=600,height=600')

Related

Why doesn't window.open(url, name) open in the SAME window with IE11?

The problem is when calling window.open(url, name) for a specific page, it is always opened in a new window, instead of the SAME one. In other words, every time this statement is executed, a new window is opened, while what I want is only ONE new window is opened and all the following calls will open the page in that new window. The name parameter in this javascript statement doesn't work for this case obviously. It only happens with IE11(Couldn't try other versions of IE).
When I tried opening window of my own pages, it worked as expected. But that specific page doesn't. That page is on the same host but out of my control. I don't know what exactly it does. The only thing I know is it relaxes document.domain. But even if I change the domain of the main page to be the same as that page's, it still doesn't work.
Does anybody know what's the root cause?
Thanks in advance!
The problem might be due to Internet Explorer settings.
Under Internet Options
Click Settings under Tabs
Under When a pop-up is encountered:, select Always open pop-ups in a
new tab
Under Open links form other programs in:, select A new tab in the
current window
to do that you want
window.location not open
open will open a new window/tab
EG
window.location = "http://www.google.com"
to navigate to google.com in the same window/tab

why is window.open(url) opening new window instead of tab

I am calling window.open(url) and Normally that would just open a new tab.
However, On this particular page i am developing, it's opening a while new small window.
i've also tried window.open(url, "_blank")
Does anyone know what would force the window to open a new window instead of a new tab.
thanks.
The behavior is completely up to the browser and how it chooses to handle it. Most browsers open a new tab when _blank is used. There is nothing that can be done programmatically to control the behavior.

How to open a link in new window with tab enabled

I search a lot but could not figured it out.
Is it possible to open a new window with tab enabled using window.open() method?.
The way chrome context menu "open link in new window" works.
The browser decides on its own how links will open. Sometimes a user can configure how links are to be opened, but the web page cannot do this.
using an anchor tag you can set the target attribute to have some control over where the link opens. Other than that, this behavior is up to the browser and user and cannot be controlled by javascript.
Use this code
window.open("http:.//www.google.com","DemoName",'scrollbars=1,height=650,width=1050');

Opening URL in New Tab doesn't work in existing, programmatically-opened New Window (Firefox)

I am building a web app, for myself, to control some servers on my home network, and discovered what I think is very odd behavior in Firefox.
If you open a pop-up, via javascript, in Firefox, is it then impossible to open a new tab, via javascript in that pop-up? If not impossible, how do you do it?
Given a clean, default Firefox 3.6.3 installation...
If I open a page in Firefox and then call
var my_window = window.open('http://www.google.com','_blank','top=10');
A brand new "pop-up" window opens.
However, if instead I call
var my_window = window.open('http://www.google.com');
A get a new tab.
HOWEVER...
If I call the first version
var my_window = window.open('http://www.google.com','_blank','top=10');
And then in the new "pop-up" that opens, I call
var my_window = window.open('http://www.google.com');
It opens a new tab in the original window, not a new tab in the pop-up.
This seems very odd, and not intuitive at all. Why would the call in the pop-up open a tab in the "parent" window?
This behavoir is a browser setting, the user desides if he opens a new window or a new tab when he opens a link. You cannot manipulate this.
Only thing you can manipulate is if you open the link in a "blank" screen, current window or certain frame
They are both children of the original document and modal windows generally do not have children. They are the rough equivalent of modal dialogs in the Windows OS. In fact, that is what IE does; it even calls it a modal dialog. I think that what is being described here is a new browser instance and not a window with tabs.

Open popup window with open.window not work?

does anybody know such a problem, window.open()do not work with Firefox suddenly.
<a href="javascript: void(0)"
onclick="window.open('popup.html',
'windowname1',
'width=200, height=77');
return false;">Click here for simple popup window</a>
this always open in a new window (or a new tab), but not open in a popup window.
Thanks,
I find that your code works perfectly. I pasted it into a new HTML page, clicked the link (using Firefox) and voila, new window.
My guess is that you're trying to use the link from a window that already has the name of the window you're trying to create. If the page is presented in a window whose name is already "windowname1", then the browser will put the results of you javascript action in that window instead of popping up a new one.
For example, if the code above is on a page named "popup.html" (the name of the file you open in window.open statement) then it will work the first time (since you haven't yet created a window named "windowname1". Then if you try to click the link again in the new window that popped up (whose name is windowname1), it will just refresh the same window instead of popping a new one.
I don't see why this would happen in firefox only though. I found identical results in Firefox, Chrome, and IE.
if you want to open a pop up window, it's alert('message'). window.open always opened a full window/tab.
(Edited: Even if you specify width/height, most browser allow you to allow javascript but not allow it to resize your windows, and firefox also allows you to force new windows to new tabs)
Maybe you need to add some extra variables to the window.open() method
<a href="#"
onclick="window.open('http://url','windowname1', 'width=200,height=100,scrollbars=yes,toolbar=yes,location=yes'); return false">Link</a>
Add attribute target="_blank" to <a> tag as below. This will open as popup.
<a target="_blank" href="javascript:void(0)">...</a>

Categories

Resources