A new window pops up when a user clicks on a link
JavaScript uses the Window object's open () method to create a new browser window, which has three parameters:
window.open (Url,name,features)
URL: New window address, if omitted, a blank window pops up
Name: Names of new windows
Features: The properties of the new window.
Like what:
function Open_url (URL) { window.open (URL, "New-window", "width:320,height:480"); }
Use the "javascript:" pseudo-Protocol to invoke the above function. ("javascript:" Pseudo-protocol allows us to invoke JavaScript functions via a link)
<Body><ahref= "Javascript:open_url (' http://www.baidu.com ');">Baidu</a><Scripttype= "Text/javascript">functionopen_url (URL) {window.open (URL),"New-window","width:320,height:480");} </Script></Body>
Embed <a> tag as attribute with OnClick event handler function
<ahref="#"onclick= "Open_url (' http://www.baidu.com '); return false;">Baidu 2</a><Scripttype= "Text/javascript">functionopen_url (URL) {window.open (URL),"New-window","width:320,height:480");} </Script>
The above two methods do not have a fallback, if the user disables the browser's JAVASCRIPT1 function, such a link is useless.
Reserve retreat that is, although the browser does not support JS or the user to disable JS some of the features can not be used, but the most basic operation can still be completed successfully.
<!--the practice of reserving retreat -<ahref= "Http://www.baidu.com"onclick= "Open_url (' http://www.baidu.com '); return false">Baidu 3</a><!--a simplified version of the reserve retreat -<ahref= "Http://www.baidu.com"onclick= "Open_url (this.getattribute (' href '); return false">Baidu 4</a><!--The most streamlined version of the reserve retreat -<ahref= "Http://www.baidu.com"onclick= "Open_url (this.href); return false">Baidu 4</a><!--the This.href property provided by the DOM -
Now even if JavaScript is disabled, this link is also available.
Behavior and structure separation:
<ahref= "Http://www.baidu.com"class= "link">Baidu 5</a><Scripttype= "Text/javascript">functionopen_url (URL) {window.open (URL),"New-window","width:320,height:480");} Window.onload=preparelinks;functionpreparelinks () {varlinks=document.getElementsByTagName ('a'); for (varI=0; I<links.length; I++){ if(Links[i].getattribute ('class') == 'Link') {Links[i].onclick= function() {Open_url ( This. getattribute ('href')); return false; } } }} </Script>
The fifth chapter of JavaScript programming can be a good habit to develop