Forum Moderators: travelin cat

Message Too Old, No Replies

Problem javascript IE 5.1.6/Mac

         

letuan

6:35 pm on May 10, 2003 (gmt 0)

10+ Year Member



Hello,

The following script doesn't work ( I'm using IE 5.1.6/Mac):

<script language="JavaScript">
<!--
window.opener.location.reload(true);
window.close();
//-->
</script>';

Can someone give me some suggestions?.

Thanks.

inkfreemedia

10:25 pm on May 13, 2003 (gmt 0)



Letuan,

It's a little unclear what you want to accomplish. Including your code is big help (thanks) but also telling us what action you are trying to achieve is very useful.

It looks as if you are trying to reload and then close a window?

From your code, as posted, there are a few punctuation problems which will foul up a browser's JavaScript interpreter/compiler.

After your </script> tag, there appears to be a single quote ( ' ) character and then a semicolon.

Semicolons need to be placed at the end of each JS line of code, but NOT after the HTML closing tag </script>.

The <...> tags are HTML code. The other stuff is JS. You do need (and have properly) semicolons after your script steps, so that's not a problem.

Remove the extra characters ( the ' and the ; ) for sure.

Now, the other issue.

If you are trying to refresh the page (reload it), then you can use something like:

document.location.href = document.location.href

or just document.location

(These depend on the browser somewhat, but you should already be filtering for that as needed so I won't elaborate here. You said you were testing with IE 5.1.6 so maybe that's what's most important. That's also what I use and code for.)

letuan

9:24 am on May 14, 2003 (gmt 0)

10+ Year Member



Excuse me, there was an error while copying. In fact, my script is as follow (I'm using php):

echo '<script language="JavaScript">
<!--
window.opener.location.reload(true);
window.close();
//-->
</script>';

I re-mention hereunder my problem :
I have 2 pages A and B. The page B is opened when click on a link on page A. Now, at the page B, I want to reload the page A and close the page B. So I used the script as above. The problem is that they tell me my script didn't work with IE 5.1.6/Mac (and I don't have Mac for test). I did what you had advised :

window.opener.location.href = window.opener.location.href;

but they continue telling me that it didn't work. If possible, could you please do some test on your computer with Mac or give me another solution?

Thanks so much in advance!

Yidaki

1:29 pm on May 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



letuan,

this script works with IE 5.1.6, Netscape 7.0.1 on Mac as well as on Windows:

<script language=JavaScript>
opener.window.location.reload();
self.close();
</script>

letuan

3:08 am on May 13, 2003 (gmt 0)

10+ Year Member



Thanks for your help. I want to detail a little bit more : to open a new window, I use the following :

<a href="" target="_blank">open new window</a>.

Is it possible that it cause the problem I have?

Yidaki

10:48 am on May 13, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



><a href="" target="_blank">open new window</a>.
>Is it possible that it cause the problem I have?

Yes, letuan - this causes your problem. This tag doesn't open a external window (in Javascript sense) - it just opens a new browser instance. If you want to access a window through js, you need to create a window object first. All command like window / opener don't work if the "window" wasn't opened through a js command.

Try this intstead:

<a href="javascript:window.open('http://yoururldotcom.com')">open new window</a>

After this you can access the window through the opener command (see my last post).

There are several optional parameter that can be used with window.open like show toolbar, show location, window size (with, height) and many more. Try searching google for Javascript Window Open [google.com] ...