Results 1 to 8 of 8

Thread: Need help with self close function

  1. #1
    Join Date
    Jan 2006
    Posts
    234
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Question Need help with self close function

    Hi.

    Can someone tell me what I have to add here to have the popup window self closed if clicked somewhere?
    Code:
    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.
    Code:
    onblur="self.close()";
    Please give me a hand here.

    Thanks in advance.
    Cheng
    Cheng

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Code:
    <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.
    Last edited by thetestingsite; 12-02-2006 at 06:24 PM. Reason: Clicked post before finishing typing
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    Jan 2006
    Posts
    234
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Post

    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:
    Code:
    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
    Cheng

  4. #4
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by thetestingsite View Post
    Code:
    <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

  5. #5
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    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,
    Quote Originally Posted by mwinter
    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.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  6. #6
    Join Date
    Jan 2006
    Posts
    234
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default

    I know what you mean but I still want it to self close.
    Maybe someone else can tell me how.
    Thanks anyway.
    Cheng
    Cheng

  7. #7
    Join Date
    Aug 2006
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by thetestingsite View Post
    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.

  8. #8
    Join Date
    Jan 2006
    Posts
    234
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default

    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:
    Code:
     <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:
    Code:
     <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>
    Code:
    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();
    }
    Cheng

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •