Javascript / Popups / Simple Image Popup
This is a simple image popup that opens a new window, that is the right size for the picture. If the window is too big for the users screen, it adjusts. If it has to adjust, it also adjusts the size of the image, so that the user does not need to scroll. it is called like this: openWin(picWidth,picHeight,picName)<br>
General Details
Snippet uploaded by: Aaron Campbell
Email : snippetlibrary@ezdispatch.com
Snippet By: Aaron Campbell
<!---Head--->
<script type='text/javascript'>
//By Aaron D. Campbell
//Feel free to remove these comments
function openWin( winWidth, winHeight, picSrc )
{
var picWidth = winWidth;
var picHeight = winHeight;
var i = 1;
winWidth = winWidth + 20;
winHeight = winHeight + 100;
if ((screen.availWidth-50) < (winWidth))
{
winWidth = (screen.availWidth-50);
i = ((winWidth-20)/picWidth);
picWidth = (winWidth-20);
picHeight = (picHeight * i);
}
if ((screen.availHeight-50) < (winHeight))
{
winHeight= (screen.availHeight-50);
i = ((winHeight-100)/picHeight);
picHeight = (winHeight-100);
picWidth = (picWidth * i);
}
picWidth = Math.round(picWidth);
picHeight = Math.round(picHeight);
newWin = window.open('', '', 'height='+ winHeight + ',width='+ winWidth + 'toolbars=no, scrollbars=no' );
newWin.document.write("<html>n<head>n<title>"+ picSrc +"</title>n</head>n<body background="images/bg.gif">n");
newWin.document.write("<div style="text-align:center; ">n");
newWin.document.write("<img src="" + picSrc + "" width="" + picWidth + "" height="" + picHeight + "">n");
newWin.document.write("<br>n<br>n<form>n <input type='button' value='Close' onclick='javascript:window.close();'>n");
newWin.document.write("</form>n</div>n</body>n</html>");
}
</script>
<!---Body--->
<img src="whatever.jpg" width="xxx" height="xxx" border="0" alt="xxxxx" title="xxxxx" style="cursor:pointer; " onclick="openWin(picWidth,picHeight,'picName.jpg');" />
No Reviews to show
