Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

how to go back to previous page.

by kasmot (Novice)
on Apr 22, 2004 at 02:52 UTC ( #347193=perlquestion: print w/replies, xml ) Need Help??

kasmot has asked for the wisdom of the Perl Monks concerning the following question:

Just wanted to know if theres a function in perl that will lead me back to the previous page of my browser.

Replies are listed 'Best First'.
Re: how to go back to previous page.
by exussum0 (Vicar) on Apr 22, 2004 at 02:54 UTC
    If you are trying to control the browser, the best you are going to do is use the history object. Something like..
    <FORM> <INPUT TYPE="button" VALUE="Back" onClick="history.go(-1)"> </FORM>
    In perl, you can do a header Location: redirect to whatever the logical last page was. i.e. if you have a 2.cgi, you can send a Location: 1.cgi to the browser instead if they submit with certain values.
Re: how to go back to previous page.
by muntfish (Chaplain) on Apr 22, 2004 at 08:46 UTC

    Most browsers will send the "referring" page in the HTTP request to get the new page. So assuming your Perl is running in a fairly standard CGI environment, you can get the URL of the referring page by looking at $ENV{HTTP_REFERER} and if defined, put it in a link when you create your page.

    (Note spelling of referer, which doesn't look right to me as a Brit, is that the US spelling or is it just a mistake?).

Re: how to go back to previous page.
by BigLug (Chaplain) on Apr 22, 2004 at 03:07 UTC
    Perl itself can't control anything in your browser. Perl just prints strings*. If a webserver runs the perl script, it takes the output of said script and sends it to the browser.

    As the previous poster has pointed out, you need to output some HTML that includes some javascript that uses the history object. Or, if you know the URL of the previous page, you can use the Location header. Most browsers honor this request and send the browser to the page specified.

    *This is an oversimplification of what perl does, but it's the fundamental function of Perl when used as part of the CGI.

    "Get real! This is a discussion group, not a helpdesk. You post something, we discuss its implications. If the discussion happens to answer a question you've asked, that's incidental." -- nobull@mail.com in clpm
Re: how to go back to previous page.
by PERLscienceman (Curate) on Apr 22, 2004 at 03:25 UTC
    Although this too is a non-perl suggestion, here is another even simpler way to access the previous page (history):
    <a href=javascript:history.back()>BACK</a>
    Best of Luck.
      thanks guys for the reply.. it worked already..
      THANKS....IT WRKD

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://347193]
Approved by exussum0
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2021-10-23 19:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (88 votes). Check out past polls.

    Notices?