wood burning stoves
The moose likes Struts and the fly likes onLoad redirect Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "onLoad redirect" Watch "onLoad redirect" New topic

onLoad redirect

Pradeep Adibatla
Ranch Hand

Joined: Oct 27, 2009
Posts: 336
Hi All,

We have our home page which we have restricted only to IE and we have displayed the same message in our home page.However when it is run on other browsers the home page is getting loaded.
In index.jsp (home page) I have written a browserCheck function ...

function browserCheck(){
var browserName = navigator.appName;
if(browserName == 'Microsoft Internet Explorer')
return true;
//alert("in else");
var url=null;
//url = 'browserCheck.action';
var urlData= '<ptms:url value="/browserCheck.action"/>';
return false;
//return false;

this is processAjax function ...
function processAjax(url, callbackFun, async, args){
var xmlhttp = null;
if (xmlhttp != null && xmlhttp.readyState != 0 && xmlhttp.readyState != 4){

if (window.XMLHttpRequest){
xmlhttp = new XMLHttpRequest();
}else if (window.ActiveXObject){
xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');

if (xmlhttp != null){
xmlhttp.open('post',url, async);
//xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlhttp.onreadystatechange = function(){
if (xmlhttp.readyState == 4){
if (xmlhttp.status == 200){
var data = xmlhttp.responseText;
alert('Problem retrieving data : ' + xmlhttp.statusText);
alert('Your browser does not support xmlhttp.')

currently it is displaying the home page rather than returning false...

Ideally I want to direct to a page(browserTest.jsp) saying " please use IE only" (something on these lines) before the page loads.

Due to paucity of time(EOD) I don't think before load prevent would be feasible...... I am thinking of following options..

1) onLoad of homepage in other browsers ,Highlight the message " This ..... to be viewed in IE only" (increase font size etc)
2) put a glamorous dialog box(best popup or some style possible ) saying " please use IE only"

need inputs.thankyou!

Jinal Prakas Shah
Ranch Hand

Joined: Jun 20, 2012
Posts: 39
If you want you can check for the browser in the action only and return the error page from there rather than from the page itself. This will make you code much neat and you don't have to worry any more for the error.
Shankar Tanikella
Ranch Hand

Joined: Jan 30, 2011
Posts: 329

Hi Pradeep,

1. Please use code tags
2. Check if "navigator.appName" works fine in all browser
3. Has Jinal mentioned use server side code and a global error page instead of JavaScript, what if the client browser java script is diabled?

Have Fun with Java
little,little.. little by little makes a lot..
I agree. Here's the link: http://aspose.com/file-tools
subject: onLoad redirect
It's not a secret anymore!