GeeCON Prague 2014*
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
Author

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(){
//alert("hai");
var browserName = navigator.appName;
if(browserName == 'Microsoft Internet Explorer')
return true;
else{
//alert("in else");
var url=null;
//url = 'browserCheck.action';
var urlData= '<ptms:url value="/browserCheck.action"/>';
//alert(urlData);
processAjax(urlData,test,false,null);
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){
xmlhttp.abort();
return;
}

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

if (xmlhttp != null){
xmlhttp.open('post',url, async);
//xmlhttp.setRequestHeader('Accept','message/x-jl-formresult');
//xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlhttp.onreadystatechange = function(){
if (xmlhttp.readyState == 4){
if (xmlhttp.status == 200){
var data = xmlhttp.responseText;
callbackFun(data,args);
}else{
alert('Problem retrieving data : ' + xmlhttp.statusText);
}
}
}
xmlhttp.send(null);
}else{
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!

Regards,
Pradeep
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..
 
GeeCON Prague 2014
 
subject: onLoad redirect