|
||||
Using the httpRequest object, check the page header to trap the page status. If Domino serves iFramed pages, you can easily support custom applications status codes, if needed.
//helper function
function reGetUrlParameter( name , url ){
//from http://www.netlobo.com
name = name.replace(/[[]/,"\[").
replace(/[]]/,"\]");
var regexS = "[\?&]"+name+"=([^]*)";
var regex = new RegExp( regexS );
var results = regex.exec( url );
if( results == null ){
return "";
}else{
return results[1];
}
}
//get the httpRequest object
function getHttprequestObject(){
//from http://www.w3schools.com
var mime = 'text/xml';
if(window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
xmlhttp.overrideMimeType(mime);
}else if(window.ActiveXObject){
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
}
//check the iframed page and present
something nice if it is not available function checkUrl(){
var params = xmlhttp.getResponseHeader("Set-Cookie");
//these params can be set in a computed for
display field; use @SetHTTPHeader
var releasestatus = reGetUrlParameter
("someparamfromdoc", params);
var pagestatus = xmlhttp.status;
if( pagestatus==200 ){
if( someparamfromdoc=="wrongstate" ){
stattxt = "Iframed page has wrong internal state."
}
}else if( pagestatus==401 ){
stattxt = "Iframed page is not accessable with
your current access right."
}else if( pagestatus==404){
stattxt = "Iframed page has been deleted."
}
if(stattxt != ""){ iframeHtml = stattxt }
document.write( iframeHtml );
}
//just give the url to this function
function startUrlCheck(testUrl){
getHttprequestObject();
xmlhttp.open("HEAD", testUrl, false);
xmlhttp.onreadystatechange = function(){
if (xmlhttp.readyState==4){
checkUrl()
}
}
xmlhttp.send(null);
}
startUrlCheck(iLnk);
Do you have comments on this tip? Let us know.
This tip was submitted to the SearchDomino.com tip library by member Steen Grunds. Please let others know how useful it is via the rating scale below. Do you have a useful Lotus Notes, Domino, Workplace or WebSphere tip or code snippet to share? Submit it to our monthly tip contest and you could win a prize.
This was first published in April 2008