PDA

View Full Version : Simple Pop ups


ThisCharmingMan
04-27-2006, 08:36 PM
I have a gallery of pictures on a site and i want to have the image that is clicked opened up in its own window that is sized accordingly to the picture as well have links to the next picture in the series. I know theres a javascript way to do it, but i'd perfer not to use that, or atleast as little as possible just because i want a friendly page that even slower computers can handle. So is there there a simple way to make this happen with Html? or css perhaps? - Luke

_Aerospace_Eng_
04-27-2006, 08:57 PM
You will need javascript in some form or fashion. Would you want a popup window or possibly a div that popups with the image in it?

ThisCharmingMan
04-27-2006, 09:13 PM
yeah, i kind of figured that, but i was hoping.... What would a div that pops up look like?

_Aerospace_Eng_
04-27-2006, 09:40 PM
Will all of the larger images be the same size?

ThisCharmingMan
04-27-2006, 10:18 PM
no, not all of them. some though.

_Aerospace_Eng_
04-28-2006, 03:43 AM
Here is a working example.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Div Popup</title>
<base href="http://students.db.erau.edu/~rodri97f/test/" />
<style type="text/css">
html, body {
margin:0;
padding:0;
font-size:0.85em;
font-family:Verdana, Arial, Helvetica, sans-serif;
background-color:#000;
color:#FFF;
}
a, a:link, a:visited {
color:#FFF;
background-color:inherit;
text-decoration:underline;
}
a:hover, a:active {
text-decoration:none;
}
#imghold {
border:1px solid #FFF;
background-color:#06F;
text-align:center;
color:#000;
display:none;
padding:4px;
position:absolute;
top:50%;
left:50%;
}
#imghold img {
border:1px solid #FFF;
clear:both;
display:block;
cursor:pointer;
}
#imghold a {
height:20px;
display:block;
line-height:20px;
}
</style>
<script type="text/javascript">
function popUp(url,wid,hgt)
{
document.getElementById('theimg').src = url;
document.getElementById('theimg').onclick = function()
{
this.parentNode.style.display = 'none';
}
document.getElementById('imghold').style.display = 'block';
document.getElementById('imghold').style.marginTop = -1 * ((hgt + 30) / 2) + 'px';
document.getElementById('imghold').style.marginLeft = -1 * ((wid + 10) / 2) + 'px';
}
</script>
</head>

<body>
<div id="imghold"><img id="theimg" src="" alt="" /><a href="#" onclick="this.parentNode.style.display = 'none';return false">Close</a></div>
<a href="cookies.jpg" onclick="popUp(this.href,355,266);return false">Cookies</a><br />
<a href="night.jpg" onclick="popUp(this.href,355,266);return false;">Night Time</a><br />
<a href="speaker.jpg" onclick="popUp(this.href,201,266);return false;">Speakers</a>
</body>
</html>

kewa
04-28-2006, 10:42 AM
I've been trying to create a popup to display a picture in a web page when the user clicks on a link.

My code is:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=windows-1252">
<TITLE></TITLE>
<META NAME="GENERATOR" CONTENT="OpenOffice.org 2.0 (Win32)">
<META NAME="AUTHOR" CONTENT="Kewa">
<META NAME="CREATED" CONTENT="20060427;14030244">
<META NAME="CHANGEDBY" CONTENT="Kewa">
<META NAME="CHANGED" CONTENT="20060428;13564756">
<SCRIPT>
<!--window.focus();//-->
</SCRIPT>
</HEAD>
<BODY LANG="en-GB" DIR="LTR">
<DIV ID="Frame2" DIR="LTR" STYLE="position: absolute; top: 0.59in; left: 1.25in; width: 5.57in; height: 0.66in; border: none; padding: 0in; background: #ffffff">
<P ALIGN=CENTER><FONT COLOR="#7da647"><FONT FACE="Arial Black, sans-serif"><FONT SIZE=6>Friends
of S C</FONT></FONT></FONT></P>
</DIV>
<P ALIGN=CENTER><BR><BR><BR><BR>
</P>
<P><BR><BR>
</P>
<P><BR><BR>
</P>
<P><BR><BR>
</P>
<P><BR><BR>
</P>
<P><BR><BR>
</P>
<DL>
<DL>
<DL>
<DD>
<TABLE WIDTH=534 BORDER=1 CELLPADDING=4 CELLSPACING=3>
<COL WIDTH=104>
<COL WIDTH=94>
<COL WIDTH=95>
<COL WIDTH=92>
<COL WIDTH=89>
<TR VALIGN=TOP>
<TD WIDTH=104 HEIGHT=13>
<P ALIGN=CENTER><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt"><B>About
SC</B></FONT></FONT></P>
</TD>
<TD WIDTH=94>
<P ALIGN=CENTER><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt"><B><A HREF="/c:/SCMap.jpg" TARGET="popup" ONCLICK="window.open('','popup','height=400,width=400,scrollbars=no)"><SPAN LANG="en-GB"><FONT SIZE=2 STYLE="font-size: 9pt"><FONT FACE="Arial, sans-serif">How
to find us</FONT></FONT></SPAN></A><SPAN LANG="en-GB"><FONT SIZE=2 STYLE="font-size: 9pt"><FONT FACE="Arial, sans-serif">
</FONT></FONT></SPAN></B></FONT></FONT>
</P>
</TD>
<TD WIDTH=95>
<P ALIGN=CENTER><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt"><B>Friends
of SC</B></FONT></FONT></P>
</TD>
<TD WIDTH=92>
<P ALIGN=CENTER><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt"><B>???</B></FONT></FONT></P>
</TD>
<TD WIDTH=89>
<P ALIGN=CENTER><FONT FACE="Arial, sans-serif"><FONT SIZE=2 STYLE="font-size: 9pt"><B>???</B></FONT></FONT></P>
</TD>
</TR>
</TABLE>
</DL>
</DL>
</DL>
<P><BR><BR>
</P>
</BODY>
</HTML>

but whatever I change when the link is clicked it opens the picture but not reduced size.

I was particularly interested in the div approach instead of popup which sounds a much better solution for what I want and I tried amending the code posted by _Aerospace_Eng_ above. Unfortunately I'm very new to this and I don't really understand the significance of each of the sections of code.

Could someone please help me by explaining what I need to change above so when the user clicks on the link "How to find it" the picture C:/SCMap appears in a closeable frame 400X400 using the div method.

I'm sorry I'm out of my depth - I'm keen to learn but I desperately need a bit of a steer.

Thanks in antipation

_Aerospace_Eng_
04-28-2006, 11:48 AM
Well your coding is quite bad. If I were you I would go read up on HTML in general. www.htmldog.com and www.w3schools.com are great places to learn. Try it like this
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Imagetoolbar" content="no">
<title>Friends of SC</title>
<style type="text/css">
html, body {
margin:0;
padding:0;
border:0;
font-size:12px;
font-family:Arial, Helvetica, sans-serif;
height:100%;
background-color:#FFF;
color:#000;
}
a, a:link, a:visited {
color:#000;
background-color:inherit;
text-decoration:underline;
}
a:hover, a:active {
text-decoration:none;
}
#container {
width:535px;
margin:auto;
min-height:344px;
position:relative;
}
* html #container {
height:344px;
}
h1 {
font-size:200%;
color:#7DA647;
background-color:inherit;
text-align:center;
font-family:'Arial Black', Arial, Helvetica, sans-serif;
margin:0;
padding:0;
}
#content {
padding-bottom:30px;
}
#content p {
margin:0;
padding:10px;
text-align:justify;
}
#navfoot {
margin:0;
padding:0;
list-style-type:none;
position:absolute;
left:0;
bottom:0;
width:100%;
}
#navfoot li {
float:left;
}
#navfoot li a {
display:block;
text-align:center;
background-color:#CCC;
color:#000;
padding:2px 0;
text-decoration:none;
width:101px;
margin:0 2px;
border:1px solid #000;
}
#navfoot li a:hover {
background-color:#7DA647;
color:#FFF;
border:1px dashed #000;
}
#imghold {
border:1px solid #000;
background-color:#7DA647;
text-align:center;
color:#000;
display:none;
padding:5px;
width:402px;
height:420px;
position:absolute;
top:50%;
left:50%;
margin-left:-207px;
margin-top:-216px;
z-index:1;
}
#imghold img {
border:1px solid #000;
clear:both;
display:block;
cursor:pointer;
margin:auto;
}
#imghold a {
height:20px;
display:block;
line-height:20px;
}
#hold {
position:relative;
display:table;
height: 100%;
width: 100%;
text-align: center;
}
#holdcell {
width:100%;
display:table-cell;
vertical-align:middle;
position:relative;
}
</style>
<!--[if IE]>
<style type="text/css">
#holdcell {
top:50%;
left:0;
}
#holdcell #container {
top:-50%;
position:relative;
}
</style>
<![endif]-->
<script type="text/javascript">
function popUp(url)
{

document.getElementById('imghold').style.display = 'block';
document.getElementById('theimg').setAttribute("src",url);// = url;
document.getElementById('theimg').onclick = function()
{
this.parentNode.style.display = 'none';
}
}
</script>
</head>

<body>
<div id="hold">
<div id="holdcell">
<div id="container"><div id="imghold"><img id="theimg" width="400" height="400" alt="" /><a href="#" onclick="this.parentNode.style.display = 'none';return false">Close</a></div>
<h1>Friends of S C</h1>
<div id="content">
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.</p>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.</p>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.</p>
</div>
<ul id="navfoot">
<li><a href="#">About SC</a></li>
<li><a href="SCMap.jpg" onclick="popUp(this.href);return false" target="_blank">How to find us</a></li>
<li><a href="#">Friends of SC</a></li>
<li><a href="#">Link 4</a></li>
<li><a href="#">Link 5</a></li>
</ul>
</div>
</div>
</div>
</body>
</html>
You can't link to an image on your own harddrive if your page is on the web. Only you will see it. You need to upload your image to your server that your page is on.

ThisCharmingMan
04-28-2006, 12:41 PM
That is a nice little trick with divs, i might use that somewhere else. But i think i need an actual new window to pop up. I suppose i will just have to go back to a javascript. The way i know it though make it quite complicated with alot of code that makes it messy. Is there a new fashioned way that is clear cut? I will poke around some other sites and see what they have. Thanks for the help!

_Aerospace_Eng_
04-28-2006, 02:24 PM
You can make one static page and update the img dynamically.
test.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="Imagetoolbar" content="no" />
<title>Image Popup</title>
<style type="text/css">
html, body {
margin:0;
padding:0;
font-size:0.85em;
font-family:Verdana, Arial, Helvetica, sans-serif;
background-color:#000;
color:#FFF;
}
a, a:link, a:visited {
color:#FFF;
background-color:inherit;
text-decoration:underline;
}
a:hover, a:active {
text-decoration:none;
}
#imghold {
border:1px solid #FFF;
background-color:#06F;
text-align:center;
color:#000;
display:none;
padding:4px;
position:absolute;
top:50%;
left:50%;
}
#imghold img {
border:1px solid #FFF;
cursor:pointer;
}
#imghold a {
height:20px;
display:block;
line-height:20px;
}
</style>
<script type="text/javascript">
var url;
function popUp(imgwid,imghgt)
{
var hgt = imghgt + 20;
var sw = (screen.width - imgwid) / 2;
var sh = (screen.height - hgt) / 2;
imgwin = window.open('img.html','imgwin','width='+imgwid+',height='+hgt+',top='+sh+',left='+sw+',resizable=1, scrollbars=0,menubar=0,toolbars=0');
if(imgwin)
{
imgwin.window.close();
imgwin = window.open('img.html','imgwin','width='+imgwid+',height='+hgt+',top='+sh+',left='+sw+',resizable=1, scrollbars=0,menubar=0,toolbars=0');
}
imgwin.focus();
}
</script>
</head>

<body>
<div>
<a href="http://students.db.erau.edu/~rodri97f/test/cookies.jpg" onclick="popUp(355,266);url=this.href;return false">Cookies</a><br />
<a href="http://students.db.erau.edu/~rodri97f/test/night.jpg" onclick="popUp(355,266);url=this.href;return false;">Night Time</a><br />
<a href="http://students.db.erau.edu/~rodri97f/test/speaker.jpg" onclick="popUp(201,266);url=this.href;return false;">Speakers</a>
</div>
</body>
</html>

img.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Image Preview</title>
<style type="text/css">
html, body {
margin:0;
padding:0;
font-size:0.85em;
font-family:Verdana, Arial, Helvetica, sans-serif;
background-color:#FFF;
color:#FFF;
}
a, a:link, a:visited {
color:#000;
background-color:inherit;
text-decoration:underline;
}
a:hover, a:active {
text-decoration:none;
}
#imghold {
text-align:center;
}
#imghold img {
display:block;
margin:auto;
cursor:pointer;
}
#imghold a {
height:20px;
display:block;
line-height:20px;
}
</style>
<script type="text/javascript">
if(!opener)
{
window.location = "test.html";
}
if(opener)
{
onload = function()
{
document.getElementById('theimg').setAttribute('src',opener.url);
}
}
</script>
</head>

<body>
<div id="imghold"><img id="theimg" alt="" onclick="window.close()" /><a href="#" onclick="window.close();return false">Close</a></div>
</body>
</html>
The above will check to see if the img.html page was opened as a popup. If it wasn't it redirects back to test.html or w/e page you like.
This checks

kewa
05-01-2006, 10:10 AM
Thanks _Aerospace_Eng_ for your helpful reply.

The bad coding comes from building the page in MS Word rather than me writing the code. I only wish I could and will be following up your suggestions.

I've been trying to use the code you posted in Post No 8 but I'm still not getting the results I'm after.

I've tried using OpenOffice but every time I click on Web Page View from the HTML Page it crashes and closes Open Office.

If I copy your code into a blank HTML Word page and then select View in Browser it looks just how I'd expect it. The link won't open because neither the file nor the picture I'm linking to are saved to my web server at that point but up to now everything is as I'd expect it.

The problem arises when I save the code and refresh the page prior to saving the Web Page and image to the server. When I view the page online the formatting has changed so the links appear as a bulletted list rather than a formatted row and when I click on the link it opens the image in a new browser window.

I've spent hours and hours on this but don't understand why the code changes when it's saved in Word and how I can stop this happening. All I want is for when the link is pressed a picture to appear in a sized frame with no options other than to Close rather than a new browser window.

Can I resolve this, and if so how, or am I stuck unless I buy something like Front Page or Dreamweaver?

Thanks again

_Aerospace_Eng_
05-01-2006, 11:19 AM
Sighs. Don't save in word. That is why its losing the formatting. Lets get one thing straight. MS word is NOT a web page editor. DW is pretty pricy. I would recommend it over FrontPage anyday. FrontPage is just as bad as coding in MS word. However AceHTML is offering HTMLForum members a free full license of their professional coding software. Read here for details http://www.htmlforums.com/announcement.php?f=21
www.nvu.com is an alternative to DW. I heard www.htmlkit.com and www.evrsoft.com both have good editors as well. All free.

kewa
05-01-2006, 12:20 PM
Thanks a lot for your patience and advice. I shall investigate the other editors you suggest and see how I get on.

Thanks again