• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

How to include different jsp in a page based on the browser java script enabled/disabled condition?

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have a home page page formed by three jsp's i.e. header, content and footer. There are two different content jsp's whose inclusion needs to be determined based on the browser javascript enabled/disabled at runtime. Please let me know how this can be achevied.

I tried using jQuery Ajax by making a synchronous call to set a request attribute and read it, but it did not help.

Thanks
Ram charan
 
Ranch Hand
Posts: 174
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can we do like this ?

First always serve the page assuming javascript is disabled..

On load of that page.. try to run javascript.. which will reload the page.. with the one that should have been loaded if javascript is enabled.
 
Ram Charan
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
May be, but it gives a wierd user experience as it reloads the page again. Any other approaches?

Thanks,
Ram Charan
 
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try This
https://coderanch.com/t/419850/HTML-JavaScript/Check-Javascript-enableness-from-JSP
 
Chinna Eranna
Ranch Hand
Posts: 174
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can put the execution of javascript in the head part of the first response..

Is this the first page.. I mean user enters the url in the browser and reaches to this page.. or
User reaches this page.. from some other page ?
 
Ram Charan
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks swapnl. I followed the link, but facing an issue while testing sample code. Below is the code I am testing with javascript enabled

<html>
<head>
<script language="javascript" type="text/javascript">
document.getElementById("jseblock1").style.display="block";
</script>
</head>
<div id="jseblock1" style="display: none">

This is the block with javascript enabled.


</div>
</html>

The issue is, statement document.getElementById("jseblock1").style.display="block"; is not getting called even if javascript is enabled. Am I doing anything wrong here? Please help.

Thanks,
Ram Charan

 
Ranch Hand
Posts: 820
IntelliJ IDE VI Editor Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When your javascript executes, your jseblock1 is not yet rendered so to javascript it doesn't exist yet, so it cannot work.

This is why in the code example they had:



That code waits until the entire window is loaded and then tries to change the display.

yours:

tries it when it reaches that line and your element does not yet exist.
 
Ram Charan
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, my mistake. Thanks Tim, working perfectly fine now.

Regards,
Ram Charan
 
Chinna Eranna
Ranch Hand
Posts: 174
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Thanks swapnl. I followed the link, but facing an issue while testing sample code.



I dont understand.. how does this helps your question.

JSP is something that gets executed @ server.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic