GeeCON Prague 2014*
The moose likes HTML, CSS and JavaScript and the fly likes How to include different jsp in a page based on the browser java script enabled/disabled condition? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "How to include different jsp in a page based on the browser java script enabled/disabled condition?" Watch "How to include different jsp in a page based on the browser java script enabled/disabled condition?" New topic
Author

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

Ram Charan
Greenhorn

Joined: Jun 07, 2008
Posts: 16
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

Joined: Dec 08, 2009
Posts: 174

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.


- Chinna
Ram Charan
Greenhorn

Joined: Jun 07, 2008
Posts: 16
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

Joined: Aug 13, 2007
Posts: 80
Try This
http://www.coderanch.com/t/419850/HTML-JavaScript/Check-Javascript-enableness-from-JSP
Chinna Eranna
Ranch Hand

Joined: Dec 08, 2009
Posts: 174

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

Joined: Jun 07, 2008
Posts: 16
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

Joined: Apr 30, 2003
Posts: 820

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

Joined: Jun 07, 2008
Posts: 16
Sorry, my mistake. Thanks Tim, working perfectly fine now.

Regards,
Ram Charan
Chinna Eranna
Ranch Hand

Joined: Dec 08, 2009
Posts: 174

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to include different jsp in a page based on the browser java script enabled/disabled condition?