Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    New to the CF scene
    Join Date
    Jun 2004
    Location
    A planet called Earth
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy [REQ] Close window onclick and go to link

    I need a script that can do the following :

    A pop-up needs to be launched automaticlly.
    If you click in the pop-up, the window should close but you should also be redirected to a given link. And last but not least, it has to have a cookie so when the pop-up came up once, it doesn't come up anymore when the user is browsing the site.

    I hope you can help me
    Thanks in advance
    Greetings

  • #2
    Regular Coder
    Join Date
    Nov 2002
    Location
    Manchester, UK
    Posts
    533
    Thanks
    4
    Thanked 1 Time in 1 Post
    This should do the trick for you....

    insert this code to the page where you want the popup to appear

    Code:
    <script>
    
    
    function openpopup(){
    popup = window.open("popup.htm","","height=250,width=250,scrollbars=yes");
    }
    
    function get_cookie(Name) {
      var search = Name + "="
      var returnvalue = "";
      if (document.cookie.length > 0) {
        offset = document.cookie.indexOf(search)
        if (offset != -1) { // if cookie exists
          offset += search.length
          // set index of beginning of value
          end = document.cookie.indexOf(";", offset);
          // set index of end of cookie value
          if (end == -1)
             end = document.cookie.length;
          returnvalue=unescape(document.cookie.substring(offset, end))
          }
       }
      return returnvalue;
    }
    
    function loadornot(){
    if (get_cookie('poppedup')==''){
    openpopup()
    document.cookie="poppedup=yes"
    }
    }
    
    loadornot()
    </script>
    that will set a cookie so that once it has popped up, it wont do so again... unless you close the browser window and open the page again...

    as for the link in the popup, use something like this:


    Code:
    <script language="javascript">
    function dolink(url)
    {
    window.opener.location.href=url;
    self.close();
    </script>
    then your link can be from a button, image or anything... such as

    <a href='#' onclick="dolink('mypage.htm')">click me</a>

    that will then change the page in the main window and close the popup...

    hope that helps!
    }

  • #3
    New to the CF scene
    Join Date
    Jun 2004
    Location
    A planet called Earth
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    it doesn't work, sry i'm a javanoob :s
    Here's the code :

    the pop.html file:
    Code:
    <html>
    <head>
    	<title>daMusic.be : Music is our passion</title>
    
    <script language="javascript">
    function dolink(url)
    {
    window.opener.location.href=url;
    self.close();
    </script>
    
    
    </head>
    
    <body topmargin="0" leftmargin="0">
    
    
    <a href="http://www.damusic.be" target="_blank" onclick="dolink('mypage.htm')"><img 
    
    src="{template_url}/pop.jpg" border="0"></a>
    
    </body>
    </html>
    The header.html file :

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html dir="{direction}">
    <head>
    <title>{site_name}</title>
    <meta http-equiv="content-type" content="text/html; charset={charset}" />
    <link rel="stylesheet" href="{template_url}/style.css" />
    <script language="javascript" type="text/javascript">
    <!--
      function opendetailwindow() { 
        window.open('','detailwindow','toolbar=no,scrollbars=yes,resizable=no,width=680,height=480');
      }
      
      function right(e) {
        if (navigator.appName == 'Netscape' && (e.which == 2 || e.which == 3)) {
          alert("© Copyright by {site_name}");
          return false;
        }
        else if (navigator.appName == 'Microsoft Internet Explorer' && (event.button==2 || event.button == 3)) {
          alert("© Copyright by {site_name}");
          return false;
        }
        return true;
      }
      document.onmousedown=right;
      if (document.layers) window.captureEvents(Event.MOUSEDOWN);
      window.onmousedown=right;
    // -->
    </script>
    
    <script>
    
    
    function openpopup(){
    popup = window.open("pop.html","","height=300,width=400,scrollbars=no,toolbars=no");
    }
    
    function get_cookie(Name) {
      var search = Name + "="
      var returnvalue = "";
      if (document.cookie.length > 0) {
        offset = document.cookie.indexOf(search)
        if (offset != -1) { // if cookie exists
          offset += search.length
          // set index of beginning of value
          end = document.cookie.indexOf(";", offset);
          // set index of end of cookie value
          if (end == -1)
             end = document.cookie.length;
          returnvalue=unescape(document.cookie.substring(offset, end))
          }
       }
      return returnvalue;
    }
    
    function loadornot(){
    if (get_cookie('poppedup')==''){
    openpopup()
    document.cookie="poppedup=yes"
    }
    }
    
    loadornot()
    </script>
    
    
    
    </head>
    <BODY BGCOLOR=#FFFFFF LEFTMARGIN=0 TOPMARGIN=0 MARGINWIDTH=0 MARGINHEIGHT=0>
    .:to resist is to piss in the wind:.

  • #4
    Regular Coder
    Join Date
    Nov 2002
    Location
    Manchester, UK
    Posts
    533
    Thanks
    4
    Thanked 1 Time in 1 Post
    no problems! We all have to start somewhere!!

    the image which you've linked in the popup should be changed to something like this:

    <img src="{template_url}/pop.jpg" border="0" onclick="dolink('http://www.damusic.be')">

    assuming that "http://www.damusic.be" is the URL you want to appear in the main page before the popup closes?

  • #5
    New to the CF scene
    Join Date
    Jun 2004
    Location
    A planet called Earth
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Weird, the popup doesn't even appear and i don't have a popupkiller :s
    .:to resist is to piss in the wind:.

  • #6
    Regular Coder
    Join Date
    Nov 2002
    Location
    Manchester, UK
    Posts
    533
    Thanks
    4
    Thanked 1 Time in 1 Post
    try closing the browser and opening the page again - I just copied the code you posted and it worked fine.....

  • #7
    New to the CF scene
    Join Date
    Jun 2004
    Location
    A planet called Earth
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok, the popup works now, but the image isn't displayed

    *throws his keyboard through the window*
    .:to resist is to piss in the wind:.

  • #8
    Regular Coder
    Join Date
    Nov 2002
    Location
    Manchester, UK
    Posts
    533
    Thanks
    4
    Thanked 1 Time in 1 Post
    oh gosh! Maybe post the code again as you have it now?

  • #9
    New to the CF scene
    Join Date
    Jun 2004
    Location
    A planet called Earth
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    For pop.html
    Code:
    <html>
    <head>
    	<title>daMusic.be : Music is our passion</title>
    
    <script language="javascript">
    function dolink(url)
    {
    window.opener.location.href=url;
    self.close();
    </script>
    
    
    </head>
    
    <body topmargin="0" leftmargin="0">
    
    
    <img src="{template_url}/pop.jpg" border="0" onclick="dolink('http://www.damusic.be')">
    
    </body>
    </html>
    And i didn't change anything in the header.html file

    The pop.jpg file is in the right folder so ...
    .:to resist is to piss in the wind:.

  • #10
    Regular Coder
    Join Date
    Nov 2002
    Location
    Manchester, UK
    Posts
    533
    Thanks
    4
    Thanked 1 Time in 1 Post
    where is the {template_url} coming from? maybe thats not being sent to the popup window or something?

    try

    <img src="{template_url}/pop.jpg"> on its own and see if that shows. If not then I suspect the template_url isnt working in the popup...?

  • #11
    New to the CF scene
    Join Date
    Jun 2004
    Location
    A planet called Earth
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    dammit, how am i supposed to work it out ?
    Maybe just give the link manually ?
    .:to resist is to piss in the wind:.

  • #12
    Regular Coder
    Join Date
    Apr 2004
    Location
    Canada
    Posts
    302
    Thanks
    2
    Thanked 0 Times in 0 Posts
    I don't know about the cookie part but this should work for the rest of it:

    On the popped up image page:
    Code:
    [...]
    <script language="javascript" type="text/javascript">
    w=window;
    function dolink(url) { self.close();
    w.open('','main');
    w.focus();
    }
    </script>
    </head>
    <body>
    <img src="{template_url}/pop.jpg" border="0" 
    onclick="dolink('http://www.damusic.be');" 
    width="xx" height="yy" alt="pop" 
    title="click on image to close window">
    [...]
    Make sure that the parent window is named "main". Coding for main window:

    Code:
    [...]
    <script language="javascript" type="text/javascript">
    function dolink(url) { var w=window;
    w.name='main'; 
    w.open(url.href,'popup','scrollbars=1,resizable=1,width=100,height=100'); 
    return false;
    }
    </script>
    </head>
    <body>
    
    <a href="imagepoptest.html" onclick="return dolink(this);">pop image</a>
    [...]
    Last edited by llizard; 06-11-2004 at 12:18 AM. Reason: adding coding for main window


  •  

    Posting Permissions

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