Home  >  Article  >  Web Front-end  >  Summary of the method of opening a link in a new window implemented by JQuery_jquery

Summary of the method of opening a link in a new window implemented by JQuery_jquery

WBOY
WBOYOriginal
2016-05-16 18:29:061375browse
First type: The following code is for the jb51 style. All a will open in a new window
Copy code The code is as follows:




Second:
Copy code The code is as follows:




In new window Open external link
Copy code The code is as follows:

$('a[href^=" http://"]')
.attr("target", "_blank");


Third type: If you want more convenient control
The XHTML 1.0 Strict version does not support the target="_blank" attribute, but using JQuery can solve this problem very well and open the web page in a new window:
Copy Code The code is as follows:

$('a[@rel$='external']').click(function(){
this.target = "_blank";
});

/*
Usage:

*/