PDA

View Full Version : Need help with self close function



Cheng
12-02-2006, 05:15 PM
Hi.

Can someone tell me what I have to add here to have the popup window self closed if clicked somewhere?

var win=null;
function NewWindow(mypage,myname,w,h,scroll,pos){
if(pos=="random"){LeftPosition=(screen.width)?Math.floor

(Math.random()*(screen.width-w)):100;TopPosition=

(screen.height)?Math.floor(Math.random()*((screen.height-h)-

75)):100;}
if(pos=="center"){LeftPosition=(screen.width)?(screen.width-

w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
else if((pos!="center" && pos!="random") || pos==null)

{LeftPosition=0;TopPosition=20}
settings='width='+w+',height='+h+',top='+TopPosition+',left='+

LeftPosition+',scrollbars='+scroll+',location=no,directories=n

o,status=no,menubar=no,toolbar=no,resizable=no';
win=window.open(mypage,myname,settings);}I think it's something like this but I can't remember exactly.
onblur="self.close()";Please give me a hand here.

Thanks in advance.
Cheng

thetestingsite
12-02-2006, 05:22 PM
<body onblur="self.close()">


I believe is the way to do it. At least thats the way that I've done it before and it worked for me.

Cheng
12-02-2006, 05:42 PM
Hi.

Thanks for your reply.
I tried this already and it isn't working but I entered it like this at the end of the code as it is an external javascript file:
body onblur="self.close()";}Something is missing.
I did this many times before but I can't remember it now.
If you have another idea please let me know.

Thanks again.
Cheng

mwinter
12-02-2006, 05:44 PM
<body onblur="self.close()">


Please, don't ever use that. A window may lose focus for all sorts of reasons entirely unrelated to the use of the site in question. It's very frustrating to switch to another application - to check e-mail, queue an MP3, etc. - to find that what you've been looking has disappeared.

Leave the window chrome alone, and the user can close the window themselves.

Mike

thetestingsite
12-02-2006, 05:50 PM
Personally, I never use that tag in any of my designs/scripts/whatnot; however, i have found some websites that do. Also, as said above,
A window may lose focus for all sorts of reasons entirely unrelated to the use of the site in question. It's very frustrating to switch to another application - to check e-mail, queue an MP3, etc. - to find that what you've been looking has disappeared. it really is frustrating. I have told some webmasters about it, but they insist that "It's so cool, though." Personally, if I want to close a window, I have the user click on a "Click to close" link or evan a picture of an "X" in the top corner of the page that says close. Thank you Mike for pointing that out though, it really is a bad practice that should not be used in that manner.

Cheng
12-02-2006, 05:54 PM
I know what you mean but I still want it to self close.
Maybe someone else can tell me how.
Thanks anyway.
Cheng

terkini
12-05-2006, 08:11 PM
Personally, I never use that tag in any of my designs/scripts/whatnot; however, i have found some websites that do. Also, as said above, it really is frustrating. I have told some webmasters about it, but they insist that "It's so cool, though." Personally, if I want to close a window, I have the user click on a "Click to close" link or evan a picture of an "X" in the top corner of the page that says close. Thank you Mike for pointing that out though, it really is a bad practice that should not be used in that manner.

Hi guys,
I have a suggestion for this problem but I am not sure whether javascript can do this. Is it possible to do a "delay" effect on the link "Click here to close"? For example, on the page, there will be a message somewhere on the page that says "You can close this window in 10 second". After 10 second, the link "Click to close" will appear either next to the words ""You can close this window in 10 second" or the words "Click to close" totally replace the words "You can close this window in 10 second".
Other possible solution is to put the words "Click here to close this windows in 10 seconds" in grey color. After 10 second the font color will change to blue and the user can click on it to close the window.
The reason for this is that, we want the visitors to spend at least 10 second to read the content of the webpage.

Cheng
12-06-2006, 04:34 PM
Hi.

Thanks for your reply but that's not the way to do it as far as I know.
Look at the script down below, this is working but only if the link is not an URL.
If the link points to an image it is working but not if the link points to an URL.
So I think if one of the guys who is advanced in javascript coding could help out with a modification to this script would make it work.
If the link points to an URL the window opens and also closes if clicked somewhere but the window that pops up has no content in it.
That is why I think it is probably just a small thing that has to be changed.

Thanks again

Not working link:
<p align="center"><a href="http://www.mysite.com"onclick="NewWindow(this.href,'popup','350','175','no','center');return false" onFocus="this.blur()"/a>popup</a> Working link:
<p align="center"><a href="http://www.mysite.com/popup.jpg"onclick="NewWindow(this.href,'popup','350','175','no','center');return false" onFocus="this.blur()"/a>popup</a>
var win=null;
function NewWindow(mypage,myname,w,h,scroll,pos){
if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=20}
settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,re sizable=no';
win=window.open('',myname,settings);
win.document.write('<body style="margin:0;padding:0;" onblur="self.close()"><img src="'+mypage+'">');
win.document.close();
}