SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    Jul 2001
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Can this be done with java script?

    I have a exit popup on my site and when some people come to my site from like yahoo or google i don't want those people to get the popup is there a way to put urls in the Java script so it will know not to open a exit window when the referring url is google or yahoo?

    If Java script can't do it what can?

    Thanks

  2. #2
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    This function will check to see if the person came from Google or not. Imagine your popup JS function is called "popup". If they didn't come from google then the window pops up.

    Code:
    <script language="javascript" type="text/javascript">
    function checkRef() {
     if (document.referrer.indexOf('google')==-1) {
      popup();
     }
    }
    </script>
    Hope this helps!

    --Vinnie

  3. #3
    American't awestmoreland's Avatar
    Join Date
    Sep 2002
    Location
    Grand Rapids, MI
    Posts
    1,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I was obviously trying to be too complicated in the solution to this

    I used an array of approved referrers to make it easy to add/delete them rather than lots of "&&" statements in the code.

    Unfortunately, when the page loads, it just seems to hang.
    Additionally I'm getting awful problems with nulls.

    Hopefully the code posted by Vinnie will solve David's problem, in which case would someone take a look at mine and see what the problem is 'cause this has got me intrigued now?


    Cheers,

    Andy
    Code:
    <head>
      <title>Perform Action Based on Referrer</title>
        <script language="JavaScript" type="text/javascript">
        <!--
    
          var DoIPop
    		
          function ToPopOrNot(){
            if(document.referrer != null){
    //        document.write(document.referrer)
    
              var approved_referrers = new Array("Yahoo","Google");
              var referring_url = document.referrer.toLowerCase();
    
              for(loop=0; loop<=approved_referrers.length; loop++){
    
                approved_referrers[loop] = approved_referrers[loop].value.toLowerCase();
    
                if(approved_referrers[loop].search(referring_url) != -1){
                  // This is an approved referrer
                  DoIPop="No";
                }
                else{
                  // This is a non-approved referrer
                  DoIPop="Yes";
                }
              }
            }
          }
    
    
          function popper(){
            if(DoIPop="Yes"){
              // Insert code for annoying pop up here ;-)
            }
          }
    
      //-->
      </script>
    
    </head>
    
    <body onload="ToPopOrNot()" onexit="popper">
    
    </body>

  4. #4
    SitePoint Member
    Join Date
    Jul 2001
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    wow thanks guys but i don't understand how to use the code you gave me. This is the code im using for an exit popup the window dosen't come up untill they exit BUT on certain links (ads) they don't get the exit window.



    Code:
    Inside the head tag
    
    <script language="JavaScript">
    var exit=true;
    function xit()
    {
    if (exit)
    open("url to exit window");
    }
    </script>
    
    --------------------------------
    
    <body onunload="xit()"
    
    and on the ads i have 
    onclick="exit=false
    Can you please tell me the exact code i need to use or else it will go over my head lol

    I don't know how you guys code that did you do that right off the top of your head?

  5. #5
    SitePoint Member
    Join Date
    Jul 2001
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    where did vgarcia go?

  6. #6
    SitePoint Member
    Join Date
    Jul 2001
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    bump

  7. #7
    SitePoint Member
    Join Date
    Nov 2002
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    awestmoreland

    Two things jumped out at me from looking at your code.

    1) You don't need to access a .value property when using arrays

    approved_referrers[loop].toLowerCase();

    will access the array element at loop.

    2) Your loop conditions were

    loop=0;loop<=approved_referrers.length

    should be loop=0;<approved_referrers.length

    which should take care of the of the null problem you were having.

    vibes


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
  •