[英]Open image in new window
如何使用其id
在新窗口中打開圖像?
function swipe()
{
var largeImage = document.getElementById('largeImage');
largeImage.style.display = 'block';
largeImage.style.width=200+"px";
largeImage.style.height=200+"px";
}
單擊圖像時調用此函數。 現在,它在同一個窗口打開,但我想在新窗口中打開它。 如何實現這一目標?
function swipe() {
var largeImage = document.getElementById('largeImage');
largeImage.style.display = 'block';
largeImage.style.width=200+"px";
largeImage.style.height=200+"px";
var url=largeImage.getAttribute('src');
window.open(url,'Image','width=largeImage.stylewidth,height=largeImage.style.height,resizable=1');
}
HTML代碼:
<img src="abc.jpg" onClick="swipe();"/>
對於一個很有可能在主窗口后面丟失的新窗口,以及一般討厭的訪問者:
window.open('http://example.com/someImage.png');
如果我是你,我會堅持常規鏈接。
嘗試:
<img src="URL or BASE64" onclick="window.open(this.src)">
HTML:
<input type="button" onclick="test()" value="test">
JavaScript的
function test(){
url = "https://www.google.de//images/branding/googlelogo/2x/googlelogo_color_272x92dp.png";
img = '<img src="'+url+'">';
popup = window.open();
popup.document.write(img);
popup.print();
}
試試這個: https : //jsfiddle.net/ne6f5axj/10/
您必須將圖像的URL放在圖像標記中。
嘗試使用以下功能:
function newTabImage() {
var image = new Image();
image.src = $('#idimage').attr('src');
var w = window.open("",'_blank');
w.document.write(image.outerHTML);
w.document.close();
}
使用此HTML代碼調用:
<img id="idimage" src="data:image/jpg;base64,/9j/4A.." onclick="newTabImage()">
就像是
window.open(url,'htmlname','width=largeImage.stylewidth,height=largeImage.style.height,resizable=1');}
但是如果有人使用AdBlock或任何PopUp-Blocker,你可能會遇到麻煩。
window.Open("http://yourdomain.com/yourimage.gif");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.