admin管理员组文章数量:1330629
I have html page with 2 links like
<a href="/">Visit W3Schools</a>
<a href="/">Visit W4Schools</a>
I want when user clicks on one of them to open new fully powerful browser window with that link. I want user to be capable of opening more than one window from my page. I need it to work via pure JS or using jQuery. It needs to work in Safari 3 and Internet explorer 6,7,8. How to create such thing?
I have html page with 2 links like
<a href="http://www.w3schools./">Visit W3Schools</a>
<a href="http://www.w4schools./">Visit W4Schools</a>
I want when user clicks on one of them to open new fully powerful browser window with that link. I want user to be capable of opening more than one window from my page. I need it to work via pure JS or using jQuery. It needs to work in Safari 3 and Internet explorer 6,7,8. How to create such thing?
Share Improve this question edited Nov 17, 2010 at 12:50 Vincent Robert 36.2k15 gold badges83 silver badges122 bronze badges asked Nov 17, 2010 at 12:45 RellaRella 67k112 gold badges374 silver badges642 bronze badges4 Answers
Reset to default 5You can set the target attribute as _blank
.
<a href="http://www.w3schools./" target="_blank">Visit W3Schools</a>
This will open the new page in a new window or a tab depending upon the browser setting.
Target="_blank" is invalid
in js you can do this with window.open()
window.open(URL,WidowName,Options)
You have this options 1. width=300 Use this to define the width of the new window.
height=200 Use this to define the height of the new window.
resizable=yes or no Use this to control whether or not you want the user to be able to resize the window.
scrollbars=yes or no This lets you decide whether or not to have scrollbars on the window.
toolbar=yes or no Whether or not the new window should have the browser navigation bar at the top (The back, foward, stop buttons..etc.).
location=yes or no Whether or not you wish to show the location box with the current url (The place to type http://address).
directories=yes or no Whether or not the window should show the extra buttons. (what's cool, personal buttons, etc...).
status=yes or no Whether or not to show the window status bar at the bottom of the window.
menubar=yes or no Whether or not to show the menus at the top of the window (File, Edit, etc...).
copyhistory=yes or no Whether or not to copy the old browser window's history list to the new window.
http://www.pageresource./jscript/jwinopen.htm
a valid jQuery and html solution is
$("document").ready(function(){
$(".blankTarget").live("click",function(){
window.open($(this).attr("href"));
return false;
});
});
You can use <a href="blah" Target="_blank">Some text</a>
which will prompt the browser to open a new window but this can be overriden by specific user settings/configurations in some browsers.
Beyond that, you cannot force the operating system to launch a new instance of a browser from Javascript - that would be a massive security risk!
target="_blank" is the best way to solve this as it doesn't involve javascript. Please bear in mind that this attribute is frowned upon and you should really let the user decide if they want to open the linked page in a new window or the window they are currently using. W3C agree with this and as such your code will not validate using their validation tool.
Alternatively this post describes how to implement a jQuery solution.
本文标签: jqueryHow to Open Multiple stand alone browser windows using JavaScriptStack Overflow
版权声明:本文标题:jquery - How to Open Multiple stand alone browser windows using JavaScript? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742268408a2443842.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论