Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 17th, 2004, 01:25 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 119
Thanks: 0
Thanked 1 Time in 1 Post
Default Determining HTTP REFERER question?

I am working with an established .js file whereby I am needing to determine if a user is coming from a particular virtual site as to whether to expose the menu option or not on the web page. The 2 menu items BOLDED below is where I need NOT display these menu options if the user is coming from a particular site. ANY HELP OR DIRECTION IS APPRECIATED. Thank you.

Here is my code:

arMenu3 = new Array(
120, //menu width
320, //left
120, //top
"#000000", //font color
"#000000", //font mouseover color
"#EEEEEE", //background color
"#CCCCCC", //background mouseover color
"#999999", //border color
"#999999", //seperator color
"Lab Test Consent Forms","http://XXXXweb018/Legal/consent.htm#5",0,
"Order Book (LAB 202)","/hmfw7/general/lab202.pdf",0,
"Point of Care Protocols","/hmfw7/poc/index.htm",0,
"Release of Body","http://XXXXXweb01/hmfw8/HPolicy/602revdofbody.doc",0,
"Specimen Collection","/hmfw7/collections/index.asp",0,
"Transfusion Services","/hmfw7/bbprotocols/index.asp",0
 
Old May 17th, 2004, 02:20 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

I would use a server side language. I don't think this is possible in JS.

HTH,

Snib

<><
 
Old May 17th, 2004, 03:42 PM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Use the document.referrer property. Referrer is spelled correctly here, though in this usage it is often times mispelled as referer.

if (document.referrer) {
   document.write('Thanks for following the link to our site.');
}

Relying on the referrer is not always a good idea, as this information can be spoofed or omitted by the user, depends on how you're using it.

Quote:
quote:Originally posted by Snib

 I would use a server side language. I don't think this is possible in JS.
The referrer is passed from the client's browser to the HTTP server, then to the server-side language, that is how it is possible to view the referrer on the server-side.


Regards,
Rich

::::::::::::::::::::::::::::::::::::::::::
The Spicy Peanut Project
http://www.spicypeanut.net
::::::::::::::::::::::::::::::::::::::::::
 
Old May 17th, 2004, 06:17 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 344
Thanks: 0
Thanked 1 Time in 1 Post
Default

You may be able to use the DOCUMENT.REFERRER to get this value.
 
Old May 24th, 2004, 08:06 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 119
Thanks: 0
Thanked 1 Time in 1 Post
Default

I tried checking using the document.referrer command however I am not doing something right. What I did is as follows:

arMenu3 = new Array(
120, //menu width
320, //left
120, //top
"#000000", //font color
"#000000", //font mouseover color
"#EEEEEE", //background color
"#CCCCCC", //background mouseover color
"#999999", //border color
"#999999", //seperator color
if (document.referrer != "http://www.mywebsite.com")
  "Lab Test Consent Forms","http://XXXXweb018/Legal/consent.htm#5",0,
"Order Book (LAB 202)","/hmfw7/general/lab202.pdf",0,
if (document.referrer != "http://www.mywebsite.com")
  "Point of Care Protocols","/hmfw7/poc/index.htm",0,
"Release of Body","http://XXXXXweb01/hmfw8/HPolicy/602revdofbody.doc",0,
"Specimen Collection","/hmfw7/collections/index.asp",0,
"Transfusion Services","/hmfw7/bbprotocols/index.asp",0
)


However, I am getting a js error stating that I am missing a ")".

Any help or direction would be appreciated.

Thanks.
 
Old May 24th, 2004, 08:56 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

You are missing the ')' that closes the new array().

Snib

<><
 
Old May 24th, 2004, 08:59 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 119
Thanks: 0
Thanked 1 Time in 1 Post
Default

Actually it is there, I just forgot to copy that into my page. Any other suggestions?

Thanks for your time in looking at this.
 
Old May 24th, 2004, 09:06 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Savoym,

Apologies if I'm way off track...

I think you are trying to conditionally add elements to your array according to whether the referrer matches a given value. AFAIK you can't do this when you first define the array.

I would try something like the following...

 arMenu3 = new Array(
120, //menu width
320, //left
120, //top
"#000000", //font color
"#000000", //font mouseover color
"#EEEEEE", //background color
"#CCCCCC", //background mouseover color
"#999999", //border color
"#999999"); //seperator color

AddMenuOption(arMenu3, "http://www.mywebsite.com", "Lab Test Consent Forms", "http://XXXXweb018/Legal/consent.htm#5", 0);
AddMenuOption(arMenu3, "", "Order Book (LAB 202)", "/hmfw7/general/lab202.pdf", 0);
AddMenuOption(arMenu3, "http://www.mywebsite.com", "Point of Care Protocols", "/hmfw7/poc/index.htm", 0);
// more options here

function AddMenuOption(pMenuArray, pExcludeFromSite, pText, pUrl, pInt){
    if(pExcludeFromSite == "" || document.referrer != pExcludeFromSite){
        pMenuArray[pMenuArray.length] = pText;
        pMenuArray[pMenuArray.length] = pUrl;
        pMenuArray[pMenuArray.length] = pInt;
    }
}

HTH,

Chris

 
Old May 24th, 2004, 09:06 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Depending on where you've added the closing ), this is not going to work.
If you need to create a new array on the fly, the items must be separated with a , just as you have with the first few items. Inside the new array declaration, you cannot use programming logic, like if constructs.
If I were you, I would add a placeholder item, like "", at the location in the array where you want it. Then outside the array declaration, use the if logic and overwrite the item in the array with the required value.

HtH,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old May 24th, 2004, 12:07 PM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Besides the other stuff that has already been brought up... Another problem with this approach:

if (document.referrer != "http://www.mywebsite.com")

is how sure are you that is the exact string in the referrer? What if the referrer is http://www.mywebsite.com/some_page.htm ?? Your referrer check isn't going to work if there is more on the referrering URL. I would suggest using a substring check with regular expressions to find that the string "http://www.mywebsite.com" Occurs at the beginning of the document.referrer property value, instead of being the value of the property exactly.



Regards,
Rich

::::::::::::::::::::::::::::::::::::::::::
The Spicy Peanut Project
http://www.spicypeanut.net
::::::::::::::::::::::::::::::::::::::::::





Similar Threads
Thread Thread Starter Forum Replies Last Post
Question on HTTP Post dgrumbli BOOK: Professional JavaScript for Web Developers ISBN: 978-0-7645-7908-0 3 December 20th, 2006 02:03 PM
Determining the name of function dotnetprogrammer VS.NET 2002/2003 0 October 23rd, 2005 04:46 AM
change or block http referer Oliver Dempsey Classic ASP Basics 2 November 14th, 2004 04:12 PM
Http://localhost/xxx/xxx/xxx.aspx Question bekim BOOK: ASP.NET Website Programming Problem-Design-Solution 2 June 11th, 2004 09:22 PM
HTTP Status 405 - HTTP method GET .... nsakic Servlets 1 January 25th, 2004 04:50 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.