Re: JavaScript

From: Date: Mon, 26 Feb 2001 04:51:29 +0000
Subject: Re: JavaScript
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-41648@lists.php.net to get a copy of this message
From: "Deependra B. Tandukar" <deepndra@icimod.org.np> > Greetings! > > Is there any equivalent code for (JavaScript) <a > href=JavaScript:history-back(1)>Back Button</a> in php? > > This works as back button on the menu bar. > > Looking forward to hearing from you. > > regards, > DT > > Yes, but it works differently. If the user typed in the URL of your page (instead of clicking a link) then you can't go back from PHP, so you need to be careful. Here's some sample code: <?php $referer = getenv("HTTP_REFERER"); if ($referer) { $url = $referer; } else { // can't go back... try JS instead $url = "javascript:history.back()"; } echo "<a href=\"$url\">Back Button</a>"; ?> Cheers Simon Garner

« previous php.general (#41648) next »