• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Ram Charan
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • 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
 
Chinna Eranna
Ranch Hand
Posts: 174
Java
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
swapnl patil
Ranch Hand
Posts: 80
 
Chinna Eranna
Ranch Hand
Posts: 174
Java
  • Mark post as helpful
  • send pies
  • 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
  • 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

 
Tim McGuire
Ranch Hand
Posts: 820
IntelliJ IDE Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic