473,797 Members | 3,096 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Passing the referral URL between web pages via JavaScript

19 New Member
I have a web site where people are directed via links from 12 different web sites.

For example, if the user was on www.chevy.com, and they clicked on a link to win a trip to an awards show, they would then be sent to my web site to register. After they fill out their information, they press submit, and are taken to the thank-you web page. After 10 seconds they get redirected back to www.chevy.com.

Is there a way to use JavaScript to pass the original referral URL (www.chevy.com) to the thank-you page, where I can load it into a meta refresh tag?

Thanks - Tony
Oct 3 '07 #1
8 9004
dmjpro
2,476 Top Contributor
I have a web site where people are directed via links from 12 different web sites.

For example, if the user was on www.chevy.com, and they clicked on a link to win a trip to an awards show, they would then be sent to my web site to register. After they fill out their information, they press submit, and are taken to the thank-you web page. After 10 seconds they get redirected back to www.chevy.com.

Is there a way to use JavaScript to pass the original referral URL (www.chevy.com) to the thank-you page, where I can load it into a meta refresh tag?

Thanks - Tony
The code of Thank-You page will be something like this ....

Expand|Select|Wrap|Line Numbers
  1. .
  2. .
  3. .
  4. <head>
  5. .
  6. <META HTTP-EQUIV="Refresh" CONTENT="3;URL=http://www.some.org/some.html">
  7. </head>
  8. .
  9. .
  10. .
  11. .
  12. .
  13.  
Kind regards,
Dmjpro.
Oct 3 '07 #2
widevision7
19 New Member
I know how to do the meta refresh tag, but I need to pass the variable of the referral URL to the second web page.

For example - they start at www.chevy.com. They click on a link that takes them to a registration page. They fill out the registration information, and click "submit". Then they are taken to a "thank-you" page, where I redirect them after 10 seconds to their original web page of www.chevy.com.

So, I need to know how to pass the referral URL between the registration and thank-you pages.

Thanks - Tony
Oct 3 '07 #3
gits
5,390 Recognized Expert Moderator Expert
hi ...

you may pass it through a query-string that you append to the url:

Expand|Select|Wrap|Line Numbers
  1. whatever_url_you_have?referer=referal_url
in a webpage you retrieve the url with:

Expand|Select|Wrap|Line Numbers
  1. var url = window.location.href
and from that you may retrieve the query-string and the referal_url.

kind regards
Oct 3 '07 #4
Greg A
5 New Member
I know how to do the meta refresh tag, but I need to pass the variable of the referral URL to the second web page.

For example - they start at www.chevy.com. They click on a link that takes them to a registration page. They fill out the registration information, and click "submit". Then they are taken to a "thank-you" page, where I redirect them after 10 seconds to their original web page of www.chevy.com.

So, I need to know how to pass the referral URL between the registration and thank-you pages.

Thanks - Tony
Hi Tony. I would use the http referrer property and place it in a cookie.

On your registration page, create the cookie with this code in the <head>:

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. function setCookie(name,val,days) {
  3.     // DATE OBJECT
  4.     var date = new Date();
  5.     // NUMBER OF MILLISECONDS IN A DAY
  6.     var milliseconds = 86400000;
  7.     // MULTIPLY, THEN ADD TO CURRENT TIME
  8.     date.setTime(date.getTime() + (days * milliseconds));
  9.     // SET EXPIRATION VARIABLE
  10.     var expires = '; expires=' + date.toGMTString();
  11.     // CONCATENATE TO CREATE COOKIE
  12.     document.cookie = name + '=' + val + expires + '; path=/';
  13. }
  14. window.onload = function(){
  15.     if(document.referrer != ''){
  16.         // DESTROY ANY PREVIOUS DUPLICATE COOKIE
  17.         setCookie('referrer','',-1);
  18.         // CREATE COOKIE ON REGISTRATION PAGE
  19.         setCookie('referrer',document.referrer,1);
  20.     }
  21. }
  22. </script>
  23.  
Then on your thank-you page, read the cookie value, and set the redirect URL with this code in the <head>:

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. // RETURN VALUE
  3. var ret = null;
  4. // MILLISECONDS (10 SECONDS)
  5. var t = 10000;
  6. // READ COOKIE FUNCTION
  7. function getCookie(cookiename){
  8.  
  9.     // ANY / ALL COOKIES
  10.     var docCookie = document.cookie;
  11.  
  12.     // CHECK TO SEE IF A COOKIE EXISTS
  13.     if(docCookie.length > 0){
  14.  
  15.         // CONCATENATE NAME AND ASSIGNMENT OPERATOR
  16.         cookiename += '=';
  17.  
  18.         // WHERE THE COOKIE NAME IS LOCATED
  19.         var cookiestart = docCookie.indexOf(cookiename);
  20.  
  21.         // IF IT EXISTS
  22.         if(cookiestart != -1) {
  23.  
  24.             // ADD START POSITION AND NAME LENGTH
  25.             cookiestart += cookiename.length;
  26.  
  27.             // FIND END OF STORED VALUE
  28.             var cookieend = docCookie.indexOf(';', cookiestart);
  29.  
  30.             // IF SEMICOLON IS NOT FOUND
  31.             if(cookieend  == -1){
  32.                 // CORRECT LENGTH
  33.                 cookieend = docCookie.length;
  34.             }
  35.  
  36.             // RETURN COOKIE VALUE
  37.             return unescape(docCookie.substring(cookiestart, cookieend)); 
  38.         }
  39.     }
  40.  
  41.     // RETURN NULL IF NO COOKIE IS FOUND
  42.     return null;
  43. }
  44. // REDIRECT FUNCTION
  45. function backToReferrer(){
  46.     // GET COOKIE
  47.     var url = getCookie('referrer');
  48.     // INITIATE PAGE JUMP
  49.     window.location.href = url;
  50. }
  51. window.onload = function(){
  52.     // AFTER 10 SECONDS, CALL REDIRECT FUNCTION
  53.     ret = setTimeout('backToReferrer()', t); 
  54. }
  55. </script>
  56.  
You must make sure the person doesn't directly enter the URL of the registration page directly into an address bar, or comes from a bookmark. The document.referr er only works on a legitimate page jump.
Oct 3 '07 #5
widevision7
19 New Member
hi ...

you may pass it through a query-string that you append to the url:

Expand|Select|Wrap|Line Numbers
  1. whatever_url_you_have?referer=referal_url
in a webpage you retrieve the url with:

Expand|Select|Wrap|Line Numbers
  1. var url = window.location.href
and from that you may retrieve the query-string and the referal_url.

kind regards
So in my meta refresh tag, how do I reference the variable url?

[HTML] <meta http-equiv="refresh" content="2;url= +url+"> ??[/HTML]

Or like this?

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. var name = "www.mysite.com"
  3. document.write(name)
  4. document.write("<meta http-equiv="refresh" content="2;url=+name+">)
  5. </script>
Thanks - Tony
Oct 4 '07 #6
widevision7
19 New Member
Thanks for the cookie example - I will give that a try.... Tony
Oct 4 '07 #7
widevision7
19 New Member
The cookie worked great!!!

You are a genius.

Thanks - Tony
Oct 4 '07 #8
Greg A
5 New Member
The cookie worked great!!!

You are a genius.

Thanks - Tony
Glad to hear it worked!

You could also improve the script by determining if the user has cookies disabled in his/her browser. That way, you could even dynamically give them instructions on how to turn cookies on for several browsers. I usually support 3 or 4 different browsers (Firefox 1.5+, MSIE6+, Opera 8+, and now Safari 3+ since it's available for Windows).

On your first page, the Registration page, you can place this code in the window.onload function:

Expand|Select|Wrap|Line Numbers
  1. window.onload = function(){
  2.     // FAKE TESTING COOKIE
  3.     document.cookie = 'testing=123';
  4.     // IF COOKIE DIDN'T SET
  5.     if(document.cookie.indexOf('testing=') == -1){
  6.         // INSTRUCT THE USER TO ENABLE COOKIES
  7.         alert('You must enable cookies to continue!');
  8.     }
  9.     // ELSE, SET COOKIE
  10.     else {
  11.         // IF REFERRER
  12.         if(document.referrer != ''){
  13.                 // DESTROY ANY PREVIOUS DUPLICATE COOKIE
  14.                 setCookie('referrer','',-1);
  15.                 // CREATE COOKIE ON REGISTRATION PAGE
  16.                 setCookie('referrer',document.referrer,1);
  17.             }
  18.         // REFERRER ERROR
  19.         else {
  20.             // INSTRUCT USER TO NAVIGATE FROM MAIN PAGE
  21.             alert('You must come directly from our afilliate websites only!');
  22.         }    
  23.     }
  24. }
  25.  
You can replace the alerts with custom code. You could have a <div> with style="display: none;" in the <body> section of the page, and then set the display to block by Javascript. The div could have graphics and text instructions magically appear...showin g the user what to do.

(I use alerts for testing, but never for a public web page!)
Oct 4 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

1
3621
by: Consuelo Guenther | last post by:
Hello, I am having problems with passing variables between pages. I have the following: First asp page has the function: ----------------------------------------------------------------------- <script language="JavaScript"> function addProcess(addPName,addSProcess,addPIndex) { var addProcessWindow = window.open('second.asp','mywindow','width=400,height=200');
12
6559
by: Kevin Lyons | last post by:
Hello, I am trying to get my select options (courses) passed correctly from the following URL: http://www.dslextreme.com/users/kevinlyons/selectBoxes.html I am having difficulty getting the courses to pass the correct option value and then be displayed at the following URL: http://www.dslextreme.com/users/kevinlyons/selectResults.html I am passing countries, products, and courses. The first two display
1
4618
by: Kevin Lyons | last post by:
Hello, I am trying to get all of my form elements passed correctly from the following URL: http://www.dslextreme.com/users/kevinlyons/selectBoxes.html to the following URL: http://www.dslextreme.com/users/kevinlyons/selectResults.html I am passing name, email, countries, cities, products, courses, etc. The others display as they should on the subsequent page,
1
1890
by: COVAD | last post by:
To Whom It May Concern: Good morning. I am Seann P. Courtney with Covad Communications and the reason that I am contacting you is because I am looking for a referral partner to do some business with. I will pay you $400.00, free and clear, if during the normal course of your days business you can refer a T1 line to me and I am cutting checks, free and clear, for up to $175.00 if you can refer a business class SDSL line. It should be...
3
2726
by: Evan | last post by:
I have a web page with 2 frames. The left frame is running menu.aspx and the right frame is running images.aspx. When a selection is made in menu.aspx I call a method in images.aspx and pass a variable. The intention is that images.aspx will take the variable and load images into its frame (the right one) based on the variable passed. What actually happens is the method runs in the left frame and ruturns the error "Object reference not...
3
3606
by: Phil Certain | last post by:
Hi I'm building a site that has publicly available pages and password protected pages. Publicly available pages reside in: /public and password protected pages reside in: /private
1
1590
by: eatkins | last post by:
Hi All- I have a great full time, permanent opportunity with a client of mine in Jersey City, NJ. They are looking for a mid-senior level Java Developer with the following skills: minimum 4 years programming exp. Computer Science degree or equivalent Java - 3 yrs EJB, RMI or CORBA - 1yr AWT/SWING - 1yr Weblogic exp. a plus
7
6233
by: vunet.us | last post by:
Can I get the name of a referral page using JavaScript? Just really wondering...
5
10308
by: aelred | last post by:
I have a web page where a member can open up a chat window (child window) with another member. - From there the member can also navigate to other web pages. - From other pages in the site, they may also open up new chat windows with other members (just not the same one). - Each chat page is opened with the member name as the window name. - When I log off from the web page, I would like all the chat windows to automatically close. I...
0
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9538
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10470
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10214
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9067
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7561
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6803
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5459
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2935
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.