Open Means Open Means
While I was working on some HTML files which requires closing the main window when I clicked on the close button which my application provided. I used window.close() javascript to close the browser window. It works perfectly fine under Internet Explorer 6 or lesser versions (<=IE6).

However the problem comes when I tested it on the IE7 and Netscape 7.0 and Netscape 7.1. IE7 gives me a prompt which is asking whether to close the window or not. The script is not at all functioning in the Netscape browser.

After a lot of research I came to know that the problem is that we are closing the window using the script which was not opened by the script. So I made changes to the code which opens some new file in the same window using the javascript.

The new file contains the window.close() method in its onload() method of BODY tag.So the code looks like this..

function closeWindow(){
var agt=navigator.userAgent.toLowerCase();
var pos = agt.indexOf('msie');
version = navigator.userAgent.substring(pos + 5).substring(0, 1);
if((agt.indexOf("msie") != -1) && (version 7)
top.opener=top;top.close();
}else{
window.top.open("w2Close.html","_self");
}
}

This will works fine for the Internet Explorer v6 and above and Netscape v7 and above. The idea here is the browsers IE7 and Netscape support tabbed browsing so we cannot close them using window.close(). So we close the browser by opening a new file in the same window using script.

No comments

Login to post a comment

Show
  • Create an account
  • Forgot your username?
  • Forgot your password?

Related Articles

  • Using command line argument in Shell Script
  • Shell Script to demonstrate functions
  • Shell Script to Check File Permissions
  • Offer Document - Why is so important and what you have to look for?
  • Systematic Investment Planning (SIP)
  • Earn money by posting links
  • Refer your friends/colleagues and earn money
  • HTML Basics - Formatting Tags
  • Java Puzzle - Problem of Two Developers Part 2
  • Canara Bank Specialist Officers - Computer Programmer Written Exam Paper
  • About Us
  • Faqs
  • Contact Us
  • Disclaimer
  • Terms & Conditions