Prevent errors on iFramed pages with JavaScript

Errors can occur on deleted iFramed pages or when Lotus Notes users don't have page access. Fix them using JavaScript and the httpRequest object.

Related resources from SearchDomino.com:
Access form fields in iFrame through Javascript when clicking an event outside iFrame

FAQ: Lotus Notes, Domino and JavaScript

JavaScript Reference Center

After deleting an iFramed page, unsightly errors can occur. Similar errors also occur if the Lotus Notes Domino user doesn't have access to the iFramed page. The following JavaScript code can be used to avoid such errors.

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

Dig deeper on JavaScript for Lotus Notes Domino

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchWindowsServer

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchEnterpriseLinux

SearchDataCenter

SearchExchange

SearchContentManagement

Close