New window open page, a very common effect, as for the code, the general first reaction is so written:
window.open (URL);
but the mainstream browser will intercept this effect (there may be too many pop-up ads in these years, if the browser does not intercept, users can not stand) in order to prevent the window from being intercepted, it is generally the use of a tag to open a new page, using the target= "_blank" attribute of the A tag, generally use the following two methods according to the situation:1. Triggered by the Click Event New window opens:----Of course you can use a tag directly on the page, this is just for the rest of the groundwork!
<href= "http://www.baidu.com/" target= "_blank" ></a>
You can change the button that triggered the click to:
<href= "javascript:void (0)" target= "_blank" ID = "Openwindow" ></ a >
Click the event to write:
1 $ ("#openWindow"). Click (function(e) { 2 $ ( This ). attr ("href", "http://www.baidu.com/"); 3 });
in the order of event firing, the href of the A tag is modified when clicked, then the default event is triggered, then the default event of the A tag is fired, and a new page is opened. Note: If you need to open a new window, you cannot use return False,e.preventdefault () in the Click event, or the statement that interrupts the default event. 2, other situation: if there is no a tag to open the page, then we create a new a tag out, and then simulate this a-tag click eventjquery notation:
1 function Openwindow (URL) { 2 var link = $ ("<a></a>"). attr ("href", url). attr (" Target "," _blank "); 3 $ ("Body"). Append (link); 4 Link[0].click (); 5 link.remove (); 6 }
native JavaScript notation:
1 function Openwindow (URL) { 2 var link = document.createelement (' a '); 3 Link.target = "_blank"; 4 link.href = url; 5 document.body.appendChild (link); 6 Link.click (); 7 document.body.removechild (link); 8 }
JavaScript opens new window blocked issue