Open new tab in Firefox - javascript

I have this code which opens all links in my page in a new window:
<base target='_new' />
It works fine in Chrome but in IE(8) and Firefox not so. In Firefox it does open a new tab, but on a second link click it loads in the new tab but without putting this tab up front, so a user would have to click on the new tab manualy. In IE it opens a new browser window. Is there an equivalent code (..js/Jquery) to open in a new tab in all browsers?

there's no guarantee where the browser will open that new window/tab. different browsers open new windows/tabs differently, and that behavior can also be affected by browser settings.

Firefox has an option to switch to the tab immediately.
Tools -> Options -> Tabs,
"When I open a link in a new tab, switch to it immediately"
IE9 has the same option
Tools -> Internet Options -> General -> Tabs Settings
"Always switch to new tabs when they are created"
IE9 has the option of what to do with new popups.
Tools -> Internet Options -> General -> Tabs Settings
"When a popup is encountered"
- Let Internet Explorer decide ...
- Always open popups in a new tab
- Always open popups in a new window
From http://windows.microsoft.com/en-US/windows7/Tabbed-browsing-frequently-asked-questions
If you opt to let Internet Explorer decide how to display pop-ups, it
will display the pop-up in a new window if the pop-up specifies size
or display requirements. Otherwise, the pop-up is displayed in a new tab.
So the behavior is mostly left up to the user and not the developer.

You can not control this part (how to open - in tab or in window). Since this is decided by browser. More of that, you can not even rely on type of browser, since each user may select his or hers way to open new pages: always in tabs or always in new windows or some other way.

I'm not sure this applies with the "base" tag, but on links, the "target" attribute can either have one predefined keyword, or any name you want to give the new window.
The available keywords are:
_blank: opens the links in a new window or tab
_self: opens the links in the same frame as it was clicked (this is default)
_parent: opens the links in the parent frame
_top: opens the links in the full body of the window
(http://www.w3schools.com/tags/att_a_target.asp)
If you don't use one of those keywords, you can use any name you want and this name will then be used to refer to that window. This allows you to reuse a tab you opened to load a different document in it.
So by using "_new" (which is not a keyword) as the base target, you essentially say that all links must be opened in the window named "_new". At first this window does not exist, so the browser creates it (first click), and the it reuses it for all following clicks.
Use "_blank" instead so that each link opens in its own new tab.

Related

Open new tab in browser window (opened with window.open)

I have a new window opened via window.open method and in that window in content I have a link with "target=_blank".
When clicked the link opens new tab in parent window instead of the one that content was in. I also noticed that for that window (created with window.open) the Ctrl+T shortcut (to open blank tab, Firefox) does not work.
I checked window.open specs and I didn't find any option that would allow this behavior.
var a = window.open("http://www.google.pl",
"Test",
"width=640,height=480,scrollbars=yes,toolbar=yes,menubar=no,location=no,resizable=yes");
a.focus();
Setting toolbar=yes makes it work in Firefox. Any idea how to make it work in chrome?
Could you show some code?
else; try with javascript:
function OpenNew(){
window.open("http://www.google.se", "_blank");
}
Rgds

Open URL in same window from different tabs

Let's say I have this function in a javascript on my web page that loads a url from an textfield with id url:
function loadUrl()
{
var url = document.getElementById('url').value;
window.open(url, 'urlwindow');
}
If I open two tabs in my browser and opens my web page in both tabs, I want both tabs to open the url in the same window, not two separate windows. Is this possible?
In other words, I want to target window opened from another tab.
You can't control the behaviur of the user's browser: just add as target windows "_blank" and hope your user have enough recent web client that opens a new tab and not a new window.
In my experience, this works perfectly (and just like you're trying to do it) with Firefox and IE, but not with Chrome or Safari.
Firefox and IE seem to use domain-specific namespaces for target names, while Chrome and Safari seem to use browser tab-specific namespaces for target names, so in these two browsers, 'urlwindow' as seen from tab A is different from 'urlwindow' as seen from tab B.
I'm trying to find a workaround for this myself, but have not yet been successful. See Chrome/Safari: how to open the same window from different tabs or windows

target=_blank to open a tab, and if failing opening a tab, opens popup with height and width

Currently, when you give a a tag a target="_blank" property, Chrome, Firefox, and modern IE browsers will open the link in a new tab. Safari and older IE will open it in a new tab. Using window.open is consistent in opening a popup for all browsers and lets you specify height and width, but modern browsers have popup blockers that will block it. Opening a new tab with target="blank" is fine/preferred, but for the browsers that are going to open that in a popup, I'd like to specify height and width, as the popup that older IE is opening is very small.
Is there a way (besides browser detection) to open a new tab, and failing that, open a new popup with a specified height and width? I believe that there is a way to do this in the reverse order, but I'd rather have the user not see a "popup blocked" alert, and then a new tab appear.
And, yes, I know that popups are annoying and insulting and terrible. This is something being asked of me by another.
The window.open method, will work when it is associated with a click event. Is this window.open associated with a click event?
** EDIT **
I have also found that a popup (window.open) tends to get hidden accidentally by users. If possible use a modal box method (like jQuery's lightbox, thickbox, simple modal, etc).

Way to open popup in a new window

Is there any way to force IE8 to open new window only in a pop-up? I don't want to change the browser settings. I want to open it and throw Javascript window.open(). Firefox is opening it in a new window but IE8 is opening the same in a new tab. Please suggest.
hold a SHIFT button while you click on an Internet hyperlink on your browser screen. This will force the link to open in a new window
You cannot control whether a browser opens a window in a new tab or new window.
Although, one work around is to set height and width dimension in the call to window.open() alongwith disabling the addressbar and statusbar.
window.open ("http://www.example.com", "mywindow","status=0,toolbar=0,height=600,width=900");
It worked for my case, I'm not sure if this satisfies your question.

How to open current page in new window

What i want to do is when the user opens their browser and types http://xyz.com/index.html, then it should pop up a new full screen window and then display index page in that new window.
I tried with using window.open('login.html', 'new_windwo', '_self'); and it opens a new window, but then there are 2 windows — one where user typed the URL, and the 2nd that we have open in the onLoad of the first page.
I am not able to close the first window — self.close() and window.close aren’t working. I am using Firefox 3.6.
Is there is any way that I can open current page in new window, without creating duplicate?
Thanks.
No. You can't destroy a window that you didn't create with a script in the first place.

Categories