admin管理员组文章数量:1279008
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?
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?
Share Improve this question asked Apr 29, 2012 at 11:05 YoussYouss 4,23212 gold badges56 silver badges112 bronze badges 2- possible duplicate of Javascript - how can i open a link in new tab (and not new window)? – balexandre Commented Apr 29, 2012 at 11:11
- did you try with "_blank" instead of "_new"? – s427 Commented May 14, 2012 at 13:18
4 Answers
Reset to default 6there'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./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./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.
本文标签: javascriptOpen new tab in FirefoxStack Overflow
版权声明:本文标题:javascript - Open new tab in Firefox - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741266527a2368574.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论