?
Solved

Botton

Posted on 1999-12-01
19
Medium Priority
?
227 Views
Last Modified: 2012-05-04
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?
0
Comment
Question by:strider031598
  • 6
  • 6
  • 4
  • +1
19 Comments
 
LVL 4

Expert Comment

by:oubelkas
ID: 2245955
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
 

Author Comment

by:strider031598
ID: 2246056
I tried your suggestion, but the button still doesn't close the window when I use IE! :(
0
 
LVL 4

Expert Comment

by:oubelkas
ID: 2246087
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 new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 2246207
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
 
LVL 4

Expert Comment

by:oubelkas
ID: 2246242
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
 
LVL 2

Expert Comment

by:Ginger_Ed
ID: 2246252
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
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 2246343
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
 
LVL 2

Expert Comment

by:Ginger_Ed
ID: 2246507
nice
0
 

Author Comment

by:strider031598
ID: 2247021
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
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 2247122
Ginger is welcome to it, but didn't mine work?????????

Michel
0
 
LVL 4

Expert Comment

by:oubelkas
ID: 2247132
Or mine??
0
 
LVL 2

Accepted Solution

by:
Ginger_Ed earned 200 total points
ID: 2247301
does this make me a point stealer??
0
 

Author Comment

by:strider031598
ID: 2247775
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
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 2247889
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
 

Author Comment

by:strider031598
ID: 2248706
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
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 2248927
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
 
LVL 4

Expert Comment

by:oubelkas
ID: 2248931
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
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 2248964
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
 
LVL 4

Expert Comment

by:oubelkas
ID: 2249061
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

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question