SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    Procrastinator Extraordinaire lucas's Avatar
    Join Date
    Oct 2000
    Location
    Springfield, Missouri, U.S.A.
    Posts
    320
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    need to add error validation to this statement, how?

    i haven't really gotten to far into javascript, but i think i'm going to need to with a particularly annoying problem with one of my javascript statements.

    i use this statement in some of pages to take the user back to the referring page:
    Code:
    <a href="<!--#echo var="HTTP_REFERER"-->">BACK</a>
    the problem is if the page is directly accessed this code doesn't work obviously.

    error messages suck, what can i do to validate this and if a referrer isn't found then redirect it to the home page of my site?

  2. #2
    ********* obeah makeda's Avatar
    Join Date
    Jun 2001
    Location
    rollin' on dubs
    Posts
    492
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    write a function that checks to see if there is anything in your serverside variable:

    Code:
    function checkBack() {
      var sLocation;
      
      //i am assuming this php command gets what you want
      sLocation = "<!--#echo var="HTTP_REFERER"-->";
      
      /*if our location is equal to nothing, we know that it was accessed directly, so return them to homepage.
    
      Otherwise return them to the referring page.
      */
      sLocation == "" ? sLocation = "yourHompage.php" : sLocation = sLocation;
    
      document.location = sLocation;
    }
    
    
    ...
    
    <a href="#" onClick="checkBack()">BACK</a>


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
  •