A new pop up window will not obey a close command from original page.

M

Marc

I am trying to create a new window from which the original page can
close that new window. For some reason the following code will not
work. Passing the window.open command to a variable called myWindow
does not work with the mouse event, but it seems to work fine with a
javascript: URL command. I would prefer to do it with the mouse event.

Please assist. I can not find any documentation for this in any of my
books.


<!-- Code begins -->

<html>
<body>

<a href="#" onMouseDown="var myWindow=window.open('text.html',
'bobby', 'width=200, height=200');">Open</a>.
<a href="#" onMouseDown="myWindow.close();">Close</a>.

</body>
</html>

<!-- Code ends -->
 
L

Lasse Reichstein Nielsen

I am trying to create a new window from which the original page can
close that new window. For some reason the following code will not
work. Passing the window.open command to a variable called myWindow
does not work with the mouse event, but it seems to work fine with a
<a href="#" onMouseDown="var myWindow=window.open('text.html',

The contents of the onmousedown attribute value is used as the body of
a function. That means that "var myWindow" declares a local variable
in that function ....

<a href="#" onMouseDown="myWindow.close();">Close</a>.

.... which is not visible from another function.
Drop the "var" and it should work.

Btw,
'bobby', 'width=200, height=200');">Open</a>.

spaces in the configuration string confuzes some browsers. Remove the
space before "height", and it should work in more browsers.

Add ",resizable=yes". In the cases where 200x200 isn't enough (and
with user stylesheets, there can be some that you can't predict),
you should allow the user to resize the window. If the content fits,
he probably won't resize anything, so it doesn't hurt to add it.

/L
 
M

Marc

Thank you. That definately worked. I also found articles on local and
global variables, and I have a better understanding of how it works.

I will also be sure to follow the guidelines for the pop up window.

Thanks,
Marc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top