2017-06-06 71 views
1

我有一個帶有URL的網頁,顯示圖片的PHP文件。我想在新窗口中打開此圖片沒有空白頁如何在沒有_blank頁面的情況下在新窗口中打開鏈接?

現在用下面的代碼,當我點擊URL,空白頁和新窗口打開(我必須關閉每次)。我不想這個空白頁面,只有窗口有圖片

window.open('image.PNG', 'image', 'toolbar,menubar,scrollbars,resizable,height=800,width=400,left=600,top=400'); 

怎麼辦?

//編輯,如果我有

<a href="file.php">Link</a> //URL to PHP with script above 
+0

使用javascript事件防止默認和window.open。 –

+0

看到這個鏈接... https://stackoverflow.com/questions/12939928/make-a-link-open-a-new-window-not-tab – Sicha

+0

防止默認不起作用在這種情況下 –

回答

0

如果粘貼在控制檯 防止默認不起作用:

open('image.png'); 

和一個新的標籤頁中打開你想要圖片,比嘗試:

<a href = 'image.png' id = 'image'> 

document.getElementById('image').onclick = funciton(e){ 
    e.preventDefault(); 
    open('image.PNG', 'image', 'toolbar,menubar,scrollbars,resizable,height=800,width=400,left=600,top=400'); 
}; 

如果還是不行,粘貼在控制檯:

open('file.php'); 

和一個新的標籤與要,比嘗試圖片打開:

<a href = 'file.php' id = 'file'> 

document.getElementById('file').onclick = funciton(e){ 
    e.preventDefault(); 
    open('file.php', 'image', 'toolbar,menubar,scrollbars,resizable,height=800,width=400,left=600,top=400'); 
}; 

如果沒有那工程,下面評論。

相關問題