在新窗口中打开图像 [英] Open image in new window

查看:160
本文介绍了在新窗口中打开图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 id 在新窗口中打开图像?

How can I open an image in a new window by using its id?

function swipe()
{   
    var largeImage = document.getElementById('largeImage');
    largeImage.style.display = 'block';
    largeImage.style.width=200+"px";
    largeImage.style.height=200+"px";                   
}

单击图像时调用此函数。现在,它在同一个窗口打开,但我想在新窗口中打开它。如何实现?

This function is called on click on the image. Right now, it's opening in the same window, but I want to open it in a new window. How can this be accomplished?

推荐答案

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 code:

HTML code:

<img src="abc.jpg" onClick="swipe();"/>

这篇关于在新窗口中打开图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆