HyperCell (?) Link - Parsing Referrer + Cookie

Discussion in 'JavaScript' started by danfirst, Mar 20, 2008.

  1. #1
    Hi, I'm really no expert. I don't even know if this is called hypercell.
    But this seems like a simple thing, which I'm sure will be a piece of cake to the gurus out there.

    I'm using this particular javascript technique whereby when a cell in a table has "onmouseover" the cell changes color, and when the cell has "onmouseout" it goes to a link.

    A simple sample is as attached. Or basically the whole sample script is like this:
    <html>
    
    
    <head>
    <meta http-equiv="Content-Language" content="en-us">
    <script type="text/javascript">
      function link1(){
        window.location.href="http://www.google.com/"; 
      } 
    </script>
    
    <script type="text/javascript">
      function link2(){
        window.location.href="http://www.yahoo.com/"; 
      } 
    </script>
    </head>
    
    
    <body>
    <center>
    
    <table border="1" width="200" cellspacing="0" cellpadding="0" height="100">
    	<tr>
    		<td onmouseover="this.style.background='#F1F7FA';this.style.cursor='pointer'" onmouseout="this.style.background='white';" onclick="link1()" width="50%" align="center">
    		<p align="center">Link to Google</td>
    		<td width="50%" align="center">
    		&nbsp;</td>
    	</tr>
    	<tr>
    		<td onmouseover="this.style.background='#F1F7FA';this.style.cursor='pointer'" onmouseout="this.style.background='white';" onclick="link2()" width="50%" align="center">
    		Link to Yahoo!</td>
    		<td width="50%" align="center">
    		&nbsp;</td>
    	</tr>
    </table>
    
    </center>
    </body>
    
    
    </html>
    Code (markup):
    This script works great. Just that:

    1. How do we make the links open in a new window?
    2. When we click on the cells, how do we parse the REFERRER info as well as the cookie info? I find that using this script just treats the click as a new click to the link, but I'm sure that some info can be parsed.
    .
     

    Attached Files:

    danfirst, Mar 20, 2008 IP
  2. So1

    So1 Peon

    Messages:
    45
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    1. use window.open("http://google.com") instead of window.location.href
    2. what do u want to do with cookie? To get? no problems:
    	function readCookie(name)
    	{
    	  var cookieValue = "";
    	  var search = name + "=";
    	  if(document.cookie.length > 0)
    	  { 
    		offset = document.cookie.indexOf(search);
    		if (offset != -1)
    		{ 
    		  offset += search.length;
    		  end = document.cookie.indexOf(";", offset);
    		  if (end == -1) end = document.cookie.length;
    		  cookieValue = unescape(document.cookie.substring(offset, end))
    		}
    	  }
    	  return cookieValue;
    }
    
    Code (markup):
    and then do with cookieValue what u want. How to get REFERRER info i dont know
     
    So1, Mar 26, 2008 IP
  3. danfirst

    danfirst Active Member

    Messages:
    450
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #3
    Hey So1, thx alot for your help.
    Just before I read your post, I actually tried window.open.
    And the funny thing is, my initial method works, just that I had some settings wrong.
    How silly of me, searching all over for information and waiting for help.
    Guess I gotta be really careful next time.
    Thanks anyway.
     
    danfirst, Mar 28, 2008 IP
  4. So1

    So1 Peon

    Messages:
    45
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    u're welcome ))
     
    So1, Mar 28, 2008 IP
  5. So1

    So1 Peon

    Messages:
    45
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    About REFERRER... I dont cnow what u use as server-side promgramming language (i use PHP).
    U can generate JavaScript on server.

    Just an exmple on PHP:
    print "<script type='text/javascript'>var referer = " . $_SERVER['HTTP_REFERER'] . "</script>";
    If user get this page via clicking link (<a href="our_page">). $_SERVER['HTTP_REFERER'] defined, otherwise u'll get notice message of PHP-interpretator. Use if(isset($_SERVER['HTTP_REFERER'])) condition.
     
    So1, Mar 28, 2008 IP
  6. danfirst

    danfirst Active Member

    Messages:
    450
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #6
    Thx So1, nice work.
    and ya, i do use PHP.
     
    danfirst, Mar 30, 2008 IP