Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

When JS disabled, how to get back button functionality  RSS feed

 
sandeep Kumar
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I have strange requirement. It is as shown below:

When JS is disabled, there is a "back" link which when user clicks on that link, user should be navigated to previous page. Can any one please help me on this.

Thanks in advance for your inputs.

~ Sandeep.
 
B Alin
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
do you mean a button / link inside an applet ?
 
sandeep Kumar
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alin,

First of all thanks you very much for your immediate response. This will be an HTML anchor tag in JSP.

 
B Alin
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it seems that what you need is something like this :



read this : w3schools reference for <noscript>
and this : a nice article about the subject with a demo included

happy coding
 
sandeep Kumar
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alin,

I know about <noscript> tag. What I need is back button behavior(user getting navigated to previous page) for the anchor link when JS is disabled.
 
mpkpramod pramod
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As js is disabled.Try this option

Make a server call and display the previous page.
 
B Alin
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kumar,

the <noscript> tag is for the ocasion where JS is disabled,

and for the back button behaviour you need the link of the previous visited page.

The link of the previous page should be obtained from the request headers - ". That is not 100% reliable so if it's not working for your browser of choice i suggest keeping track of the last previous page by storing the link on the current session.

I found this regarding how to get request headers in JSP

happy coding

p.s. the header in question is "Referer"
 
sandeep Kumar
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ya Pramod We'll have to use some server side coding to achieve the functionalities where ever JS is diabled. But how do I capture the previous page's url in present page when JS is disabled. To be more elaborative, In my application there is a JSP say one.jsp. There are many flows through which a user gets navigated to one.jsp. In one.jsp, there is an anchor tag "back" which on click of this link, user should get navigated to the previous page form which he/she had arrived to one.jsp.
Hope this clarifies the requirement.
A small code snippet to capture the previous page's URL when JS is disabled in browser; will be helpful.
 
B Alin
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try this :

<noscript>
<a href="<%= request.getHeader("referer") %>">Back</a>
</noscript>

it doesn't matter what the flow is, it only matters what "link" the user requested

furthermore, you can't know in advance if the user's browser has JS disabled; you can only prepare for it; if the JS is enabled then the html code from this snipper will be ignored by the browser so the "Back" anchor tag will show only when the JS is disabled
 
sandeep Kumar
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your inputs Alin. As HTTP_REFERER is not 100% reliable to be used, I'm planning to use Session scoped variable from which this would be implemented.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65830
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why would you repeat a back button on your application? Why not just rely on the browser back button?

Links in your app should all go someplace concrete.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!