Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Senior Coder
    Join Date
    Jul 2005
    Location
    UK
    Posts
    1,051
    Thanks
    6
    Thanked 13 Times in 13 Posts

    Automatically Retrieve <title> of Referring Page

    Hi all,

    Title of the thread says it all really - I'm not even sure whether to be looking for a JS or PHP solution (my instinct is JS). Anyone have any ideas?

    Regards

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,539
    Thanks
    8
    Thanked 1,093 Times in 1,084 Posts
    So I assume you already are able to see what the referring page is?
    You just want to grab the title?

    Or, are you thinking about opening a log file and reading in the referring
    URLs ...

    I'm not sure how you are seeing the referral URLs to begin with.

  • #3
    Senior Coder
    Join Date
    Jul 2005
    Location
    UK
    Posts
    1,051
    Thanks
    6
    Thanked 13 Times in 13 Posts
    Sorry, the referring URL is in the query string. I'm creating a bookmarking system where you have a button on your toolbar with this JS function:

    Code:
    javascript:location.href='http://www.example.com/bookmark.php?url='+encodeURIComponent(location.href)"
    If you know del.icio.us, it's basically that kind of deal.

    EDIT: I've just realised I can probably encode the title at the same time as the URL. Doh! *potters off to try that out*
    EDIT: It works, kind of...

    These two functions work seperately to get the two bits of information I need:

    Code:
    +encodeURIComponent(location.href)
    Code:
    +encodeURIComponent(document.title)
    However, I'm not sure how to combine them to get the query string I need, which would look something like ?url=[referring url]&title=[referring title]. It's the apostrophes seperating up the link and the encodeURI functions that are playing up. Having tried the obvious (JS in red for clarity)...

    Code:
    javascript:location.href='http://www.example.com/bookmark.php?url='+encodeURIComponent(location.href)'&title='+encodeURIComponent(document.title)"
    ... I've come to the end of my javascript expertise :-D Anybody know how to toggle these two last bits together properly?
    Last edited by Pennimus; 09-01-2006 at 03:11 AM.

  • #4
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    You left out the + in href)+'&title
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

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