473,320 Members | 1,865 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Need help closing a Pop Up Window via a text link

Hi, I have a nice little script that works well displaying images on
my website. It's a script where if you clik a thumbnail image a pop
up window opens that contains a larger version of the same image. What
I would like to create is a link that can be clicked on to close the
window that contains the larger image. This would make it easier for
the users to close the window. I have posted the script that I use.
Any help would be much appreciated. I tried to find the answer in the
archives and came close but in any programing language close usually
isnt good enough...Thanks.

"Head script"

<script language="JavaScript">
<!--
function doNothing(){}

function popUp1(winFile, winHeight, winWidth) {
window.open(winFile, '', 'width=' + winHeight + ',height=' + winWidth
+',')

}
// end -->
</script>
Image Link in body:

<p><a href="javascript: void doNothing()"
onClick="popUp1('images/P5210025.jpg',265,223)"><img
src="images/images1/P5210025_small.jpg" width="125" height="93"></a>
Jul 20 '05 #1
3 5148
th********@hotmail.com (Steve) writes:
Hi, I have a nice little script that works well displaying images on
my website. It's a script where if you clik a thumbnail image a pop
up window opens that contains a larger version of the same image.
So "works well" means that it works if no popup blocker prevents to
window from openening, and if Javascript is enabeled.
What I would like to create is a link that can be clicked on to
close the window that contains the larger image.
Make it a button. Buttons are clicked for an effect. Links are clicked
to get to a new resource.

Where do you want the button placed, on the old page or the new?
This would make it easier for the users to close the window.
Depends on users. For me, using mouse gestures is faster than any
button. :)
Anyway, making it faster to close makes it sound like you want
the button on the popup page.
<script language="JavaScript">
The type attribute is required in HTML 4, and the language attribute
is not necessary when type is used:
<script type="text/javascript">
<!--
HTML-like comments are not necessary in Javascript.
function doNothing(){}
??
function popUp1(winFile, winHeight, winWidth) {
window.open(winFile, '', 'width=' + winHeight + ',height=' + winWidth
+',') .... <p><a href="javascript: void doNothing()"
onClick="popUp1('images/P5210025.jpg',265,223)"><img
src="images/images1/P5210025_small.jpg" width="125" height="93"></a>


A good example of FAQ 4.24 <URL:http://jibbering.com/faq/#FAQ4_24>.
Your page is unusable in browsers without Javascript, and it doesn't
need to be.

Make the link:
<a href="images/P5210025.jpg"
onclick=popUp1(this.href,265,223);return false;"><img
src="images/images1/P5210025_small.jpg" width="125" height="93"></a>

This works with and without Javascript. With Javascript, you control the
opening of the window. Without, the user still sees the big image.

Now, to add a close button to the popup window, you need to control
the contents of the window. As it is now, you just open the image.
To make a close button, you need to open an html page. Try this:

---
function popUp1(winFile, winHeight, winWidth) {
var w = window.open('', '',
'width='+winHeight+',height='+winWidth+',resizable =yes');
var d = w.document;
d.open();
d.writeln("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" "+
"\"http://www.w3.org/TR/html4/strict.dtd\">");
d.writeln("<html><head><title>Image<\/title>");
d.writeln("<meta http-equiv=\"Content-Script-Type\" ",
"content=\"text/javascript\"><\/head>");
d.writeln("<body style='margin:0px;padding:0px;'>")
d.writeln("<div><img src='"+winFile+"' onclick='window.close()'><\/div>");
d.writeln("<\/body><\/html>");
d.close();
}
---
This opens a popup, just as before. Then it writes HTML into it,
making an img element. It sets the onclick on the image element to
close the window, so you can click anywhere in the window to close it
(faster than any button).

Good luck
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2
Thanks Lasse for your reply and the warning about the code not working
in all browsers. The "Close" link would go next to the thumbnail image
and not in the pop up window. This way the user would only have to
click the thumbnail to view/open the pictures and then close this
window quickly by clicking the link instead of having to move the
mouse over the "X". Thank you for you for your help!

p.s. sorry about not clarifying this the first time.




Lasse Reichstein Nielsen <lr*@hotpop.com> wrote in message news:<3c**********@hotpop.com>...
th********@hotmail.com (Steve) writes:
Hi, I have a nice little script that works well displaying images on
my website. It's a script where if you clik a thumbnail image a pop
up window opens that contains a larger version of the same image.


So "works well" means that it works if no popup blocker prevents to
window from openening, and if Javascript is enabeled.
What I would like to create is a link that can be clicked on to
close the window that contains the larger image.


Make it a button. Buttons are clicked for an effect. Links are clicked
to get to a new resource.

Where do you want the button placed, on the old page or the new?
This would make it easier for the users to close the window.


Depends on users. For me, using mouse gestures is faster than any
button. :)
Anyway, making it faster to close makes it sound like you want
the button on the popup page.
<script language="JavaScript">


The type attribute is required in HTML 4, and the language attribute
is not necessary when type is used:
<script type="text/javascript">
<!--


HTML-like comments are not necessary in Javascript.
function doNothing(){}


??
function popUp1(winFile, winHeight, winWidth) {
window.open(winFile, '', 'width=' + winHeight + ',height=' + winWidth
+',')

...
<p><a href="javascript: void doNothing()"
onClick="popUp1('images/P5210025.jpg',265,223)"><img
src="images/images1/P5210025_small.jpg" width="125" height="93"></a>


A good example of FAQ 4.24 <URL:http://jibbering.com/faq/#FAQ4_24>.
Your page is unusable in browsers without Javascript, and it doesn't
need to be.

Make the link:
<a href="images/P5210025.jpg"
onclick=popUp1(this.href,265,223);return false;"><img
src="images/images1/P5210025_small.jpg" width="125" height="93"></a>

This works with and without Javascript. With Javascript, you control the
opening of the window. Without, the user still sees the big image.

Now, to add a close button to the popup window, you need to control
the contents of the window. As it is now, you just open the image.
To make a close button, you need to open an html page. Try this:

---
function popUp1(winFile, winHeight, winWidth) {
var w = window.open('', '',
'width='+winHeight+',height='+winWidth+',resizable =yes');
var d = w.document;
d.open();
d.writeln("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" "+
"\"http://www.w3.org/TR/html4/strict.dtd\">");
d.writeln("<html><head><title>Image<\/title>");
d.writeln("<meta http-equiv=\"Content-Script-Type\" ",
"content=\"text/javascript\"><\/head>");
d.writeln("<body style='margin:0px;padding:0px;'>")
d.writeln("<div><img src='"+winFile+"' onclick='window.close()'><\/div>");
d.writeln("<\/body><\/html>");
d.close();
}
---
This opens a popup, just as before. Then it writes HTML into it,
making an img element. It sets the onclick on the image element to
close the window, so you can click anywhere in the window to close it
(faster than any button).

Good luck
/L

Jul 20 '05 #3
th********@hotmail.com (Steve) writes:

(Please don't top post! At least trim the quotes!)
The "Close" link would go next to the thumbnail image and not in the
pop up window.


Much easier then. The only problem is that you can't click it if the
popup obscures it, so you have to move the popup to get to the button.

Try:

<a href="imageURL.png"
onclick="openwindow = popUp1(this.href,'','width='....);return false;">
<img src="thumbnailURL.png"></a>

<input type="button" value="Close popup"
onclick="if(openwindow && !openwindow.closed) {
openwindow=openwindow.close();}">

Inside popUp1, return the return value of the call to window.open.
That is the only reference you have to the new window, and you need
the reference in order to close the window.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: timmy_dale12 | last post by:
I need help with this one. I have a function that pastes a row. In each row i am pasting a link which is to call a date picker javascript function. This is the code that pastes the link : link =...
8
by: Johnny Knoxville | last post by:
I've added a favicon to my site (http://lazyape.filetap.com/) which works fine if you add the site to favourites the normal way, but I have some JavaScript code on a couple of pages with a link,...
2
by: Derek | last post by:
Hello: I want to capture the event when a browser is closing, to give to the user the posibility of close or no this browser. When the browser is closing, this show a confirm window with two...
4
by: bbass | last post by:
thanks to all that replyied to my previous post with the following code in question: <a href="merc.htm" target="_new_merc" onfocusout=window.close class="left_link"> i understand that the...
7
by: Rich | last post by:
I have the following script on all pop up windows, would like to have this work on all newer browsers if possible. Right now it only works on MSIE & Opera. Not sure why. Any suggestions are...
12
by: adamurbas | last post by:
ya so im pretty much a newb to this whole python thing... its pretty cool but i just started today and im already having trouble. i started to use a tutorial that i found somewhere and i followed...
7
by: ojsimon | last post by:
Hi I found this script on a forum and have been trying to make it work, but all it returns is a blank screen, i tried using the debug error reporting but got nothing from that either just a blank...
7
by: sumanta123 | last post by:
Dear All, How will we do in JSP page on closing the parent window the child windows should close automatically. I will show my code Please i will show you my code. For HTML link function...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.