標籤:status pen col getattr div 頁面 lan elinks color
<!DOCTYPE html><html lang="en" dir="ltr"> <head> <meta charset="utf-8"> <title></title> </head> <body> <a href="https://www.baidu.com/" class ="popup"> 百度一下</a> <!-- onclick = ‘return false‘ ,點擊後不跳轉了 --> <script type="text/javascript"> // 輔助函數 var addLoadEvent = function(func) { var oldonload = window.onload; //將已有的儲存,如果已有 if (typeof window.onload !== ‘function‘ ) { window.onload = func; } else { window.onload = function(){ oldonload(); func(); } } } addLoadEvent(prepareLinks); // 主函數 function prepareLinks() { // 此處表達成var prepareLinks = function(){ , 則函數無效,到這就不運行了??? if(!document.getElementsByTagName) return false; var links =document.getElementsByTagName(‘a‘); for (var i = 0; i < links.length; i++) { if (links[i].getAttribute(‘class‘) == ‘popup‘) { //包含了 對 ‘popup‘ 是否存在的判斷 links[i].onclick = function(){ return popUp(this.getAttribute("href")) ? false : true; //return !popUp(this.getAttribute("href")); } } } } // 點選連結 不跳轉頁面 ,快顯視窗 var popUp = function(winURL) { window.open(winURL,"popup","resizable,scrollbars,status"); return true; } // 若 popUp 改成如下,則點選連結 在同一視窗下開啟 新標籤頁面 // var popUp = function(winURL) { // window.open(winURL, ‘_blank‘); // return true; // } </script> </body></html>
window open 快顯視窗 和 同一視窗下開啟新標籤頁