[問題] Javascript如何在背景開新視窗
使用的瀏覽器是Chrome
今天試著使用JavaScript抓圖片網址並在新視窗打開
開視窗的code有試過兩種
一個是 window.open(url, "_blank");
有試過配合 .focus() .blur() 的用法 但都無效
另一個是
function openNewBackgroundTab(url){
var a = document.createElement("a");
a.href=url;
var evt = document.createEvent("MouseEvents");
//the tenth parameter of initMouseEvent sets ctrl key
evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, true,
false, false, false, 0, null);
a.dispatchEvent(evt);
}
openNewBackgroundTab(url);
這方法也是不能
請問正確的寫法是怎樣??
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 180.176.83.78
※ 文章網址: https://www.ptt.cc/bbs/Ajax/M.1431104524.A.C43.html
※ 編輯: andy14 (180.176.83.78), 05/09/2015 01:10:00
※ 編輯: andy14 (180.176.83.78), 05/09/2015 01:53:03
→
05/09 08:23, , 1F
05/09 08:23, 1F
推
05/10 00:32, , 2F
05/10 00:32, 2F
請問能有更詳細的說明嗎 因為才剛接觸 不太明白
上網找的文章說onload目的好像是等網頁讀取完成才執行
不過我是應用在Chrome的userscript 正常網頁應該已經讀取完了
還是有什麼其它的onload用法??
我有去試過 window.onload
還是無法改善視窗開在前面的問題
※ 編輯: andy14 (180.176.83.78), 05/10/2015 01:58:14
→
05/10 15:24, , 3F
05/10 15:24, 3F