/    Sign up×
Community /Pin to ProfileBookmark

how 2 get previous page’s url?

I’m a javascript novice but I found the code that will provide a javascript back button. However I don’t need to actually go back one page, I just need the url from the previous page> Here is what I have so far (which doesn’t work). As you see, I’m trying to get the previous url into a php variable.

$go_history = “”;
$go_history .= “<script LANGUAGE=’JavaScript’>showHistory(-1)</script>”;
echo ‘go history = ‘, $go_history;

Strangely, if I replace showHistory with goHistory that line acts just like a refresh and goes to the previous page. I’ve tried a few different variations also
Any help is greatly appreciated.

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@Declan1991Oct 18.2007 — You cannot get Javascript variables into PHP and you cannot get the URI of the previous page anyway. Try:
[code=php]
$ref=@$HTTP_REFERER;
echo $ref;
[/code]
Copy linkTweet thisAlerts:
@MinutemanauthorOct 18.2007 — Well, you got me headed in the right direction.

Furl is the social network I've used so I looked at the link they use and, sure enough you were right. They pull the referrer and put it innto the link and goes through tothe page as a post var.

Thanks

here's the link that does it

javascript:d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:'')?d.getSelection?d.getSelection():'');d.location.href='http://www.bungeebones.com/bungee_jumpers/social_network.php?p=1&t='+encodeURIComponent(XPCNativeWrapper(document,'title','UTF-8').title)+'&u='+escape(d.location.href)+'&r='+escape(d.referrer)+'&v=1'+'&c='+escape(t);
Copy linkTweet thisAlerts:
@Declan1991Oct 18.2007 — BTW I wasn't very clear there. Javascript cannot get the URI of the previous page in the history, but PHP can get the referring page. The only thing Javascript can do is send you back or forward through the history.
Copy linkTweet thisAlerts:
@ZeroKilledOct 19.2007 — there is something similar on javascript. try document.referrer

in firefox it work even if the previous link don't come from the same site. but to work, it has to be followed by a link, not by typing the url on the address bar. of course, you can only get one link back, no more futher.

my english look crippy, sorry, not my native language
Copy linkTweet thisAlerts:
@Declan1991Oct 19.2007 — Yes, ZeroKilled is right (I never knew about document.referrer) but you must use a link to get to the page. The PHP solution is better and will work regardless of whether Javascript is enabled.
×

Success!

Help @Minuteman spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...