homepage Welcome to WebmasterWorld Guest from 54.197.65.82
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
how to insert a close button/link on a small pop up window
contentmaster

10+ Year Member



 
Msg#: 2740 posted 7:33 am on Nov 16, 2004 (gmt 0)

There is a small window that opens on load of my home page and it stays there for 10 secs and closes on its own after 10 secs .... is there a simple code taht i can insert in m html so that the visitors have the option to close the window if they want to before the 10 secs?

Help Please

 

Paul in South Africa

10+ Year Member



 
Msg#: 2740 posted 12:02 pm on Nov 16, 2004 (gmt 0)

Not tested but should get you started

Somewhere where you have your Javascript insert

function clswin() {
close();}

Then you can call the clswin function using something like

<a onclick="clswin();" href="#"><IMG border="0" src="images/close_1.jpg"></a>

making sure that your image is referenced correctly or using appropriate text.

Lance

10+ Year Member



 
Msg#: 2740 posted 12:32 pm on Nov 16, 2004 (gmt 0)

Or: (Looks like a button)

<button onclick="self.close();">Close Me</button>

Or: (Looks like a link)

<a href="#" onclick="self.close();">Close Me</a>

Or: (Looks like plain text)

<a onclick="self.close();">Close Me</a>

Or for that matter, if you put the "onclick=" in your <body> tag, clicking anywhere in the small window will close it.

<body onclick="self.close();">

adni18

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 2740 posted 12:57 pm on Nov 16, 2004 (gmt 0)

The <button> tag is not completely compatible with all browsers. try this:

<input type=button onClick="if(window.opener){window.close()}else{alert('This page is not being displayed as a popup.')}">

contentmaster

10+ Year Member



 
Msg#: 2740 posted 7:32 am on Nov 18, 2004 (gmt 0)

Or: (Looks like a link)

<a href="#" onclick="self.close();">Close Me</a>



I tried to insert this link on the small window (this is a script that i am using - which shows a small pop up type of page over my original page which closes automatically in 10 secs) and on clicking this link a window appears asking if i want to close the window...on pressing yes the entire page closes...even my home page!:((

What should be done so that only the small window closes and not my home page?

dreamcatcher

WebmasterWorld Senior Member dreamcatcher us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 2740 posted 9:36 am on Nov 18, 2004 (gmt 0)

Try the following:

<a href="javascript:self.close()">Close Me</a>

:)

Lance

10+ Year Member



 
Msg#: 2740 posted 2:31 pm on Nov 18, 2004 (gmt 0)

What should be done so that only the small window closes and not my home page?

Did you put the link in the small window, or in the home page itself? It needs to be in the small window.

Bernard Marx

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 2740 posted 2:40 pm on Nov 18, 2004 (gmt 0)

[pre]
<input type="button"
value="Click Here for instructions in closing this window"
onclick="alert('Closing this window:\nClick the small black X at the top corner of the window')" />
[/pre]

adni18

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 2740 posted 2:46 pm on Nov 18, 2004 (gmt 0)

Or: <a href="#" onClick="window.close()">close</a>

contentmaster

10+ Year Member



 
Msg#: 2740 posted 9:26 am on Nov 21, 2004 (gmt 0)

I am putting the codes in the small window.but the main web page is closing ...what is happening!

adni18

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 2740 posted 6:08 pm on Nov 21, 2004 (gmt 0)

have you tried these codes in other browsers? maybe the problem lies there.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved