Botton

I was using the following code to close javascript windows, but I later found out it was only working with Navigator and not IE:

<form name="close">
<center><input type="button" value="Close" onCLick="window.close();
</form>

The code makes an HTML button that SHOULD close a JS window, but it doesn't work with Microsoft's browser.  Is there something I can do to make it compatible with both browsers?
strider031598Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

oubelkasCommented:
Well first of all, close the code properly :

<form name="close">
<center><input type="button" value="Close" onClick="window.close();"></center>
</form>
 
Then, it should work in both IE and NS. Use the name of the opened window to close it ( e.g. myWindow.close(); )

the close() method is compatible in both IE and NS

Joseph
0
strider031598Author Commented:
I tried your suggestion, but the button still doesn't close the window when I use IE! :(
0
oubelkasCommented:
Try this :

blabla.html

<HTML>
<HEAD>
<script language="javascript">
<!--
function window2Up(){
  window2=window.open("win2.html", "win2","height=200, width=200");
}
// -->
</script>
</head>


<body>
<form>
<input type="button" value="open window 2" onClick="window2Up()">
<input type="button" value="close window 2" onClick="window2.close()">
</form>
</body>
</html>

win2.html

<html>
<body>
window 2
</body>
</html>

Now open the window with the button, and then close it...it works...

Joseph

0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

Michel PlungjanIT ExpertCommented:
Joseph, you mean "use the window handle" not the name
in "Use the name of the opened window to close it ( e.g. myWindow.close(); ) "

Michel
0
oubelkasCommented:
Sorry, Michel,

you're right, mixed up....it should be the window handle, thus like window2 in the last comment I gave. The name is defined with the properties (like "win2").

Joseph
0
Ginger_EdCommented:
i was having a look at this and the first script should work, in fact it does if you add <Script Language = "JavaScript"></Script>

to the head, you don't need to put any code in their but it needs to be there.

So if you change your origional script ot:

<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
</SCRIPT>

</HEAD>
<BODY>

<P>&nbsp;</P>
<form name="close">
<center>
<input type="button" value="Close" onClick="window.close()">
</form>

</BODY>
</HTML>


It should work and it will give the msg that it is trying to close itself.  Has anyone else found this that if you don't add the script tags even though they aren't needed, the script doesn't run??

0
Michel PlungjanIT ExpertCommented:
Hmmm - If you have VB scripts on the same page I have seen this.

The correct syntax to use is this then:

<input type="button" value="Close" language="javascript" onCLick="window.close();">

Michel
0
Ginger_EdCommented:
nice
0
strider031598Author Commented:
I tried all suggestions and the one that worked for me was Ginger Ed's. So GE, if you want the points, just repost as answer. :)
0
Michel PlungjanIT ExpertCommented:
Ginger is welcome to it, but didn't mine work?????????

Michel
0
oubelkasCommented:
Or mine??
0
Ginger_EdCommented:
does this make me a point stealer??
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
strider031598Author Commented:
Guys, I honestly tried all of your suggestions, and no doubt that Michel's LOOKED like the best, but it didn't work.  The only one that worked was Ginger Ed's. Anyway, thanks to all of you.
0
Michel PlungjanIT ExpertCommented:
No seriously, I have no problem with the points, only the fact that I seemed to be misinformed.

I have found the actual problem

change form name=close to
name=closeit
and you will be just fine.

the problem is you used a reserved word for the form name.

Michel
0
strider031598Author Commented:
Michel, your last suggestion turned out to be right.  I'm wondering, though, if close is a reserved word, then how come it worked when I added the lines

<Script Language = "JavaScript"></Script>

above the code?  Hmm...weird.
0
Michel PlungjanIT ExpertCommented:
One never knows ;-)

Possibly for the same reason that I thought language=javascript would work - that IE defaults the scripting engine to JScript instead of VBScript.

Michel
0
oubelkasCommented:
Well, as far as  I know, I never add <Script Language = "JavaScript"></Script>

when using the close() method. Indeed, hmmm....weird. Ah well.

Joseph
0
Michel PlungjanIT ExpertCommented:
Joseph, IE was only reacting to having the form named close and then a function executing window.close

since IE scopes the variables in a "userfriendly" way, you can sometimes access variables of the document via the window object
so naming the form close, overwrote the close method of the window object.

window.close=null;
would do the same to the button...

Michel
0
oubelkasCommented:
Oh, yes, of course. Mmm, so the best thing here to say to strider is,

"It's best not to use reserved words as names for objects"

Yep, yep...

Joseph
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.