Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript close and reload parent issue with Safari

Status
Not open for further replies.

fmrock

Programmer
Sep 5, 2006
510
US
Hey Everyone,

I have a asp page that pass a form to another asp page which does some database updates.

In the bottom of the update.asp page i have the following Javascript.

Code:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Chart Update</title>
</head>
<% 
Response.Write("<script type=""text/javascript"">opener.location.reload();</script>")
Response.Write("<script type=""text/javascript"">window.close();</script>")
%>
<body>
</body>
</html>


This works fine in IE, but in safari, it does not close the broswer or reload the parent page that popped up this window.

Any suggestions? Thanks
 
you may find the method is different for different browsers, so it might be .refresh() for example.

Aslo i beleive you need self.close();

If you are firing pop-up windows purely to rund scripts / server code and then just close them, how about using a hidden iframe on the main page for these operations, or looking at AJAX as an alternative.

pop-ups = bad! ;-)

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
How you determine the type broswer and then do the specific types of close/refresh.

If broswer=ie Then
opener.location.reload();
window.close();
Else

End if
 
BTW.. im not poping the new window just for server scripts... it basicly a whole wizard step process that gets opened in a new broswer. Once the steps are complete i want to close it, and refresh the parent that opened it.
 
I've used this script for detecting browser
Code:
// Check for browser function
function Browser() {

  var ua, s, i;

  this.isIE    = false;
  this.isNS    = false;
  this.version = null;

  ua = navigator.userAgent;

  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as NS 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
}

// Create browser object
var browser = new Browser();

Then use
Code:
if (browser.isIE)
      do this
    if (browser.isNS)
      do that;

You just need to find out what other browser report as and then edit the JS to accomodate.

hope it helps

:)


"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
In order to close the window and for that fact opening a window using window.open I use a variable to do the work for me. Example
win=window.open(...); win.focus(); win.close(); If you are using a pop up window You can create a function on the opener to reload the opener and a function in the pop up to close itself. The function might go like this
win.close();
I have also needed to use this little trick which fools the pop up to thinking it is the parent and closes itself. This trick is really for when your pop up is a tab instead of a pop up this may because of how you open it or how the browser is set.
window.open('','_parent','');window.close();
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top