Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Image in a new window?

Status
Not open for further replies.

egims

Technical User
Jun 5, 2001
96
US
After clicking on a thumbnail of an image I would like a larger version of the image to appear in a new window.

The method I am currently using works in part, but leaves a good sized white border on the top and left of the image in the new window, and cuts off part of the right and bottom of the image that is displaced. I need a method which will not do that.

Thanks.
 
egims,

i would use this in first page (the one with the thumbnail):
---mybeautifulpic.htm is the url of the new window.
---mypicwin is just a name for the new window.

<SCRIPT language=&quot;JavaScript&quot;>
<!--
function img1win() {window.open(&quot;mybeautifulpic.htm&quot;,&quot;mypicwin&quot;,&quot;height=300,width=400,left=50,top=50&quot;);}
// -->
</SCRIPT>


in the body of this first window you might have a link to call the new window:

<a href=&quot;javascript:img1win()&quot;>
<img src=&quot;mybeautifulthumbnail.jpg&quot; width=&quot;80&quot; height=&quot;60&quot; border=&quot;0&quot;>
</a>


Now the window that will pop up, most important is the Body tag:(Topmargin, Leftmargin,marginwidth and marginheight get rid of the nasty browser border):

<html>
<head>
<title>My Beautiful PIC!title>
</head>

<BODY BGCOLOR=&quot;#000000&quot; TOPMARGIN=0 LEFTMARGIN=0 MARGINWIDTH=0 MARGINHEIGHT=0>
<center>
<img src=&quot;mybeautifulbigpic.jpg&quot; width=&quot;400&quot; height=&quot;300&quot; border=&quot;0&quot;>

---you may want to close the window?
<a href=&quot;javascript:window.self.close()&quot;>close me!</a>
</center>
</body>
</html>


Hope it helps ;)

~ jsLove
 
jsLove,

Thanks but this is not quite what I am looking for. I do not want to call another html document at all - as in your above example &quot;mybeautifulpic.htm&quot; in which I can control the border via the body tag.

What I am looking for is the ability to have an individual click on a thumbnail and have the larger image display in a window that will contain it without a border - and without the need to use another entire html document.

But thanks much anyway.
 
egims,

what it sounds like you are after ....

when you say &quot;new window&quot; it tends to mean an html document.

i think, however, you may be more interested in using DHTML or commononly refered to as &quot;Layers&quot; ....there is a DHTML Forum. Hope it helps ;)

~ jsLove
 
egims,

How about this:
<script language=&quot;JavaScript&quot;>
function showimg(image) {

this_image = new Image();
this_image.src = image;
image_w = this_image.width;
image_h = this_image.height;

var win = window.open(&quot;&quot;, &quot;win&quot;, &quot;width=&quot; + image_w +&quot;,height=&quot; + image_h + &quot;&quot;); // a window object

var sMarkup = &quot;<HTML><HEAD><TITLE>New Document</TITLE></HEAD>&quot;;
sMarkup += &quot;<BODY marginwidth=0 marginheight=0 topmargin=0 leftmargin=0>&quot;;
sMarkup += &quot;<img src=&quot; + image + &quot;>&quot;;
sMarkup += &quot;</BODY></HTML>&quot;;

with (win.document) {
open(&quot;text/html&quot;, &quot;replace&quot;);
write(sMarkup);
close();
}
}
</script>


and a test I ran:
<html>
<head>
<script language=&quot;JavaScript&quot;>
function showimg(image) {

this_image = new Image();
this_image.src = image;
image_w = this_image.width;
image_h = this_image.height;

var win = window.open(&quot;&quot;, &quot;win&quot;, &quot;width=&quot; + image_w +&quot;,height=&quot; + image_h + &quot;&quot;); // a window object

var sMarkup = &quot;<HTML><HEAD><TITLE>New Document</TITLE></HEAD>&quot;;
sMarkup += &quot;<BODY marginwidth=0 marginheight=0 topmargin=0 leftmargin=0>&quot;;
sMarkup += &quot;<img src=&quot; + image + &quot;>&quot;;
sMarkup += &quot;</BODY></HTML>&quot;;

with (win.document) {
open(&quot;text/html&quot;, &quot;replace&quot;);
write(sMarkup);
close();
}
}
</script>
</head>
<body>
<a href=&quot;javascript:showimg('/images/est_logo.gif');&quot;>show image est_logo.gif</a>
</body>
</html>


Now remember, there is a minimum height for a window. If you want to go even smaller than the minimum, you will have to use DHTML (layers, etc. to create a pseudo popup with hide/show commands).

Chad. ICQ: 54380631
 
Here is a DHTML method you can use (I grabbed this from DynamicDrive):

1. Place this in the <head></head> of your page:
<script>

//Thumbnail image viewer-
//© Dynamic Drive (//For full source code, usage terms, and 100's more DHTML scripts, visit
var ie=document.all
var ns=document.layers
var ns6=document.getElementById&&!document.all

function enlarge(which,e){
//Render image code for IE 4+ and NS6
if (ie||ns6){
crossobj=document.getElementById? document.getElementById(&quot;showimage&quot;) : document.all.showimage
if (crossobj.style.visibility==&quot;hidden&quot;){
crossobj.style.left=ns6? pageXOffset+e.clientX : document.body.scrollLeft+event.clientX
crossobj.style.top=ns6? pageYOffset+e.clientY : document.body.scrollTop+event.clientY
crossobj.innerHTML='<div align=right id=drag><b onClick=closepreview()>X</b></div><img src=&quot;'+which+'&quot;>'
crossobj.style.visibility=&quot;visible&quot;
}
else
crossobj.style.visibility=&quot;hidden&quot;
return false
}
//Render image code for NS 4
else if (document.layers){
if (document.showimage.visibility==&quot;hide&quot;){
document.showimage.document.write('<a href=&quot;#&quot; onMouseover=&quot;drag_dropns(showimage)&quot;><img src=&quot;'+which+'&quot; border=0></a>')
document.showimage.document.close()
document.showimage.left=e.x
document.showimage.top=e.y
document.showimage.visibility=&quot;show&quot;
}
else
document.showimage.visibility=&quot;hide&quot;
return false
}
//if NOT IE 4+ or NS 4, simply display image in full browser window
else
return true
}

function closepreview(){
crossobj.style.visibility=&quot;hidden&quot;
}

</script>


<script language=&quot;JavaScript1.2&quot;>

//By Dynamicdrive.com

//drag drop function for NS 4////
/////////////////////////////////

var nsx,nsy,nstemp

function drag_dropns(name){
temp=eval(name)
temp.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP)
temp.onmousedown=gons
temp.onmousemove=dragns
temp.onmouseup=stopns
}

function gons(e){
temp.captureEvents(Event.MOUSEMOVE)
nsx=e.x
nsy=e.y
}
function dragns(e){
temp.moveBy(e.x-nsx,e.y-nsy)
return false
}

function stopns(){
temp.releaseEvents(Event.MOUSEMOVE)
}

//drag drop function for IE 4+ and NS6////
/////////////////////////////////

function drag_drop(e){
if (ie&&dragapproved){
crossobj.style.left=tempx+event.clientX-offsetx
crossobj.style.top=tempy+event.clientY-offsety
}
else if (ns6&&dragapproved){
crossobj.style.left=tempx+e.clientX-offsetx
crossobj.style.top=tempy+e.clientY-offsety
}
return false
}

function initializedrag(e){
if (ie&&event.srcElement.id==&quot;drag&quot;||ns6&&e.target.id==&quot;drag&quot;){
offsetx=ie? event.clientX : e.clientX
offsety=ie? event.clientY : e.clientY

tempx=parseInt(crossobj.style.left)
tempy=parseInt(crossobj.style.top)

dragapproved=true
document.onmousemove=drag_drop
}
}

document.onmousedown=initializedrag
document.onmouseup=new Function(&quot;dragapproved=false&quot;)


</script>


2. Place this directly under your <body> tag:
<div id=&quot;showimage&quot; style=&quot;position:absolute;visibility:hidden;border:1px solid black&quot;></div>

3. Setup your thumbnail or text links that will popup the images:

either
<a href=&quot;photo1.jpg&quot; onClick=&quot;return enlarge('photo1.jpg',event)&quot;><img src=&quot;thumbnail.gif&quot; border=&quot;0&quot;></a>
or
<a href=&quot;photo1.jpg&quot; onClick=&quot;return enlarge('photo1.jpg',event)&quot;>This is a text link</a>

Have fun!

Chad. ICQ: 54380631
 
Thank you very much inlandpac & jsLove.

Your help is much appreciated.

Best,

Ed
 
inlandpac,

I know its been awhile since this thread stopped being active, but if you don't mind I have a question about your solution.

Your solution seems to work GREAT in Explorer, but for some reason in Navigator 4.08 when the new window appears with the image in it, only the height seems to work. The width is sized about twice the actual image width.

The image inside the window appears fine, but there is a huge block of white space to the left of the image due to the expanded width in Navigator 4.08.

Trust Navigator to be a pain. Do you have any idea of why, or how to correct the problem?

Thanks,

Ed
 
egims,

Well, you are right...trust NS to be a pain.

To be honest, this should work for IE4+, NS6, and NS4.

Very strange.

I will look into this and will get back with you.

Chad. ICQ: 54380631
online.dll
 
Hi Chad,

I was just wondering if you may have had an opportunity to give that problem any further thought?

Best,

Ed
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top