Forum Moderators: coopster & phranque

Message Too Old, No Replies

Homebrew no-JavaScript "Back" button

Do it yourself!

         

Everyman

3:45 am on Dec 31, 2001 (gmt 0)




Homebrew no-JavaScript "Back" button for dynamic pages:

Here's a neat trick if you need a "Back to previous page" link on a dynamically-generated page. May seem obvious to everyone, but I just thought of it after using the JavaScript equivalent for a year. I hate JavaScript, and now with this trick, my sites are 100 percent JavaScript free.

All you do is write a script that catches the HTTP_REFERER. Let's put this in a string called "refstring".

Then you do this:

Status: 301
Location: refstring
(two newlines and exit)

I tried it on IE and Netscape. The 301 status defeats the browser's inclination to grab what's in its cache. Instead it does a reload.

You can even plant a cookie before you do this. I use it to offer a "Java" or "No Java" cookie (I'm talking Java and not JavaScript), and then reload the previous page. The previous page then loads according to which cookie was chosen by the user. Really clean, and it skips the stupid intermediate page of "Click this, and then do a refresh of your page" stuff I had before -- it goes right to the new page instantly.

I'm so happy I discovered this. And I feel so stupid for taking a year to think of it!

Xoc

5:02 am on Dec 31, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Note that that won't work if someone uses Opera with Referrer's turned off.

Everyman

5:36 am on Dec 31, 2001 (gmt 0)



Yes, but it will still plant the cookie in my case, which means that it will work a couple pages ahead.

How many use Opera with REFERER turned off, as opposed to using every other browser with JavaScript turned off?

I'll bet lots of folks have JavaScript turned off, if only because 1) Netscape can't handle lots of JavaScript written for IE, and 2) those damn pop-under ads that JavaScript makes possible, and 3) JavaScript is a security risk for email in Outlook Express as well as for worms that can be downloaded from infected websites.