Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
possible using cookies/javascript to change text depending on 'from page'?
Old 12-22-2010, 05:35 AM possible using cookies/javascript to change text depending on 'from page'?
Novice Talker

Posts: 8
Trades: 0
Hi All,

Glad i found this place seems like there are a lot of activity here!

I'm doing some online marketing work for the company im with. I need to see if this idea of mine is possible? i don't need a tutorial, just if it's possible and roughly how.

What i want to do is change a line of text on a website depending on which landing page someone comes from. so for example:

type in removed in browser or just normal visit (phone number is 0800 000 000)

come from landing page 1 ---> removed (all the places that display the phone number will be automaticly changed to 0800 111 111)

come from landing page 2 ---> removed (all the places that display the phone number will be automaticly changed to 0800 222 222)

come from landing page 3 ---> removed (all the places that display the phone number will be automaticly changed to 0800 333 333)

etc...

Anyone know if this is something thats possible with clever coding?

Thank you!

Last edited by chrishirst; 12-22-2010 at 10:29 AM..
arnoldma is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-22-2010, 08:16 AM Re: possible using cookies/javascript to change text depending on 'from page'?
Extreme Talker

Posts: 246
Trades: 0
Yes, it is.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
stbuchok is offline
Reply With Quote
View Public Profile
 
Old 12-22-2010, 09:09 AM Re: possible using cookies/javascript to change text depending on 'from page'?
Novice Talker

Posts: 8
Trades: 0
Thanks stbuchok, can you give me a rough idea how please? i'm i right in thinking you have to use a piece of javascript code on the landing page, and edit the pages on removed with some code around the phone numbers i wish to change?

If i need to get this done by a freelancer how much is reasonable?

Thanks.

Last edited by chrishirst; 12-22-2010 at 10:30 AM..
arnoldma is offline
Reply With Quote
View Public Profile
 
Old 12-22-2010, 09:28 AM Re: possible using cookies/javascript to change text depending on 'from page'?
Extreme Talker

Posts: 246
Trades: 0
You can do it a few different ways, one would be to use cookies (serverside or client side), another would be that each landing page populates a session variable (for PHP or .Net) and then you use the session variable where ever needed.

As for how much this should cost I would say ~10 minutes per page * $30/hour normally at a min of $50 - $100 total (I'm not a freelancer so this could be wrong).

The 10 minutes per page should cover testing and uploading of the pages.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
stbuchok is offline
Reply With Quote
View Public Profile
 
Old 12-22-2010, 09:32 AM Re: possible using cookies/javascript to change text depending on 'from page'?
Novice Talker

Posts: 8
Trades: 0
thanks again stbuchok! very helpful information, reputation added
arnoldma is offline
Reply With Quote
View Public Profile
 
Old 12-22-2010, 10:31 AM Re: possible using cookies/javascript to change text depending on 'from page'?
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Bearing in mind of course that the referrer field (the URI where the click occured) is not always carried with the HTTP Request to the server.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 12-22-2010, 10:54 AM Re: possible using cookies/javascript to change text depending on 'from page'?
Novice Talker

Posts: 8
Trades: 0
Thanks chrishirst, is there a way to do it so that it is always carried with the HTTP request, if there isnt would the tracking rate be more or less than 80%? considering the person has cookies enabled.
arnoldma is offline
Reply With Quote
View Public Profile
 
Old 12-22-2010, 03:46 PM Re: possible using cookies/javascript to change text depending on 'from page'?
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Nope, the referrer field is optional in the HTTP request and is often disabled by Internet security programs.

The only way to be sure of tracking the source of clicks is use a unique URI to point to each landing page.

Or if the referring pages are on the same domain you could of use sessions or cookies to carry a code.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 12-23-2010, 04:46 AM Re: possible using cookies/javascript to change text depending on 'from page'?
Novice Talker

Posts: 8
Trades: 0
Quote:
Originally Posted by chrishirst View Post
Nope, the referrer field is optional in the HTTP request and is often disabled by Internet security programs.

The only way to be sure of tracking the source of clicks is use a unique URI to point to each landing page.

Or if the referring pages are on the same domain you could of use sessions or cookies to carry a code.
Yeah the referring pages are on the same domain, i have posted this job on a freelance website based on your suggestions, think i will go down the cookie route. cheers!
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
arnoldma is offline
Reply With Quote
View Public Profile
 
Old 12-24-2010, 03:46 AM Re: possible using cookies/javascript to change text depending on 'from page'?
Marik's Avatar
Skilled Talker

Posts: 99
Trades: 0
Not tested but this should work:

Code:
<script type="text/javascript">
<!--

    var referrer = document.referrer;

    if (referrer == 'http://mydomain.com/pageone.html/') {
    var phone = '0800 111 111';
    }
    else if (referrer == 'http://mydomain.com/pagetwo.html/') {
    var phone = '0800 222 222';
    }
    else if (referrer == 'http://mydomain.com/pagethree.html/') {
    var phone = '0800 333 333';
    }
    else {
        var phone = '0800 000 000';
    }

//-->
</script>
Then in all the places where the phone number should appear use:

Code:
<script type="text/javascript">document.write(phone);</script>
__________________

Please login or register to view this content. Registration is FREE
Marik is offline
Reply With Quote
View Public Profile
 
Old 12-24-2010, 03:58 AM Re: possible using cookies/javascript to change text depending on 'from page'?
Marik's Avatar
Skilled Talker

Posts: 99
Trades: 0
Quote:
Originally Posted by chrishirst View Post
The only way to be sure of tracking the source of clicks is use a unique URI to point to each landing page.
This is a better way to do it, in this case the OP can use the following:

Code:
On page one:

<a href="landingpage.html?pid=1">Go to Landing Page</a>

On page two:

<a href="landingpage.html?pid=2">Go to Landing Page</a>

On page three:

<a href="landingpage.html?pid=3">Go to Landing Page</a>
On the landing page have this javascript:

Code:
<script type="text/javascript">
<!--

    function gup(name) {
      name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
      var regexS = "[\\?&]"+name+"=([^&#]*)";
      var regex = new RegExp( regexS );
      var results = regex.exec( window.location.href );
      if( results == null )
        return "";
      else
        return results[1];
    }

    var pid = gup('pid');

    if (pid == 1) {
        var phone = '0800 111 111';
    }
    else if (pid == 2) {
        var phone = '0800 222 222';
    }
    else if (pid == 3) {
        var phone = '0800 333 333';
    }
    else {
        var phone = '0800 000 000';
    }


//-->
</script>
And use this everywhere the phone number should appear:
Code:
<script type="text/javascript">document.write(phone);</script>
p.s. I didn't write the grab url parameter function, that's courtesy of this site: http://www.netlobo.com/url_query_string_javascript.html
__________________

Please login or register to view this content. Registration is FREE
Marik is offline
Reply With Quote
View Public Profile
 
Old 12-24-2010, 06:29 AM Re: possible using cookies/javascript to change text depending on 'from page'?
Novice Talker

Posts: 8
Trades: 0
This is great Marik, thank you! i will test this and see if it works, would save me some money on a freelancer if it does so much appreciated.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
arnoldma is offline
Reply With Quote
View Public Profile
 
Old 12-24-2010, 07:13 AM Re: possible using cookies/javascript to change text depending on 'from page'?
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
Originally Posted by Marik View Post
This is a better way to do it, in this case the OP can use the following:
So that will
Quote:
Originally Posted by chrishirst View Post
The only way to be sure of tracking the source of clicks is use a unique URI to point to each landing page.
So rather than a better way" you have simply transcribed what I suggested into code
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 12-24-2010, 12:57 PM Re: possible using cookies/javascript to change text depending on 'from page'?
Marik's Avatar
Skilled Talker

Posts: 99
Trades: 0
Quote:
Originally Posted by chrishirst View Post
So that will

So rather than a better way" you have simply transcribed what I suggested into code
That's what I said, the way you suggested (using different URL's pointing to the page) is the better way to do it instead of doing it through referrer or cookies. I was giving you a compliment actually .
__________________

Please login or register to view this content. Registration is FREE
Marik is offline
Reply With Quote
View Public Profile
 
Old 12-24-2010, 01:06 PM Re: possible using cookies/javascript to change text depending on 'from page'?
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
It was just the way it was worded no offence taken and none intended.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to possible using cookies/javascript to change text depending on 'from page'?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.45788 seconds with 12 queries