Results 1 to 2 of 2

Thread: document.referrer in JS

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Denmark
    Posts
    1,049

    Question document.referrer in JS

    I want to use the object document.referrer because I need some information on the URL I have visited before the actual site. I have used this function where I want to write my previous site to a text field, but nothing happens. What could be wrong?
    Code:
    function tester() {
    	if (document.referrer == "http://intranet") {	
    		sprog = "Not OK";
    		document.calc_heat.test.value=sprog;
    		} 
    	else {
    		sprog = document.referrer ;
    		document.calc_heat.test.value=sprog;
    		} 
    	
    }

  2. #2
    Fanatic Member punkpie_uk's Avatar
    Join Date
    Sep 2001
    Location
    UK
    Posts
    645
    Hi,

    I take it the form is called calc_heat and the text field is called test?

    I tested it using your code and worked fine for. Bearing in mind that it was run from a webserver, it will return nothing if its run from a folder.

    If you put an Alert(document.referrer) in the code does it still return nothing?

    This is what I used...

    page 1 code
    Code:
    <html>
      <head>
        <title>Untitled</title>
      </head>
      <body>
        <a href="page2.htm">Page2</a>
      </body>
    </html>
    page 2 code
    Code:
    <html>
      <head>
        <title>Untitled</title>
        <script language="JavaScript" type="text/javascript">
        <!--
           function tester() {
    	if (document.referrer == "http://intranet") {	
    		sprog = "Not OK";
    		document.calc_heat.test.value=sprog;
    		} 
    	else {
    		sprog = document.referrer ;
    		document.calc_heat.test.value=sprog;
    		} 
    	
          }
        //-->
    </script>
    
    </head>
    <body onload="tester()">
    <form name="calc_heat">
       <input type="text" name="test">
    </form>
    </body>
    </html>
    SPREAD THE WORD!!! Are You Lee McCormick? Because I Am



    Lee M McCormick
    [email protected]

    Lee McCormick.com - Live
    Dynamically Webbed.com - In development but live

Posting Permissions

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



Click Here to Expand Forum to Full Width