PDA

View Full Version : Fullsize image window popup script.


DrDOS
09-19-2010, 04:37 PM
This converts an ordinary 'opens in the same window' HTML page into one with a fullsize click to close popup window. Just link to the script. You can make it ignore URLs you don't want to link to by changing the start and end of the count.

function showImg(URL){
var imgPage="<html><head><title>Click to Close " + URL + "</title><style>body{background-color:#333;color:#d0ffd0;text-align:center}table{width:100%;height:100%;text-align:center}td{text-align:center;vertical-align:middle}img{border:5px solid #d0ffd0}<\/style></head><body onLoad='self.focus();' onClick='self.close();' ><table><tbody><tr><td><img src='" + URL + "'><\/td><\/tr><\/tbody><\/table><\/body><\/html>";
var mywin=open('','','scrollbars=0,toolbar=0');mywin.document.write(imgPage);mywin.document.close();}
function popupWindows() {
if(!document.getElementsByTagName) {
return;
}
var anchors = document.getElementsByTagName("a");
for (var i = 0; i < anchors.length; i++) {
var anchor = anchors[i];
var imgURL = anchor.getAttribute("href");
anchor.setAttribute("href","#");
anchor.setAttribute("onClick","javascript:showImg('" + imgURL + "');");
}}
window.onload = popupWindows;

Here it is in action. It can be a little wonky at times.

http://ronbeau.50webs.com/newalbum/images2.html

Kor
09-21-2010, 11:04 AM
Your code will not work in IE. IE does not consider the events as attributes, thus it has another event model. Moreover: the token javascript: is medieval and useless. The modern JavaScript simply uses events to call a function.

Why don't you have the patience to learn some real JavaScript instead of posting inefficient and wrong codes packed up as useful?

Philip M
09-27-2010, 05:32 PM
Why don't you have the patience to learn some real JavaScript instead of posting inefficient and wrong codes packed up as useful?

Seconded. :p Please refrain from vomiting your undigested code over this group.