...

View Full Version : window.open function



sunzini
03-22-2005, 06:14 AM
Hi, ive been studing javascript for a little bit, and ive been giving 9 exercise that involve createing a new window, each one of these has the same problem beacause there basically the same just adding more stuff as we go along.

my code is exactly like my handouts so it has to be somthing simple that the teacher forgot or is being sneaky, i dont want any drastic changes please.


----------------------function----------------------------------



function MakeA Win(){
win=window.open("","results","toolbar=yes,width=200,height=200,directories=yes
,status=yes,scrollbars=yes,resize=yes,menubar=yes");
win.document.write("<html><head><title>Window2</title></head>");
win.document.write("<body><h3 align=center>WindowOne</h3>");
win.document.write("</body></html>");}



--------------------------form button------------------------

<form action="">
<input type="submit" name="mywin" value="Create Window!"
onclick="MakeA Win()" />
</form>

----------------------------------------------------------------

this is just bugging me!

glenngv
03-22-2005, 07:16 AM
What's your question? You didn't mention the problem you're talking about.

But judging from the script you posted, I can guess that the problem seems to be in the function name. Space is not allowed in function names. Is that a typo?

sunzini
03-22-2005, 07:36 AM
it doesn't open a new window, try it yourself. And i dont think it's the space in the function name.

warhammerdude20
03-22-2005, 07:50 AM
Aside from the function name, you haven't got a comma between
directories=yes and status=yes...

glenngv
03-22-2005, 08:39 AM
And the button must be a regular button and not a submit button.

<input type="button" ...>


and document should be closed after the last document.write.

win.document.close();


The popup window may also be blocked by popup blocker installed in your system (if any)

sunzini
03-22-2005, 09:11 AM
i tried all the suggestions and it still doesn't work. Could somebody try the javascript on their browser?

Im just wondering why my lecturer would make me do it this way.

glenngv
03-22-2005, 09:57 AM
Can you post the whole and final code of the page that you're working with? Also what browser are you using?

sunzini
03-22-2005, 10:03 AM
sure, here it is. Im using firefox, but ive used opera, and IE


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>New Window</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="standard.css" rel="stylesheet" type="text/css" />
<script language="JavaScript" type="text/javascript">
<!--
function MakeA Win(){
win=window.open("","results","toolbar=yes,width=200,height=200,directories=yes
,status=yes,scrollbars=yes,resize=yes,menubar=yes");
win.document.write("<html><head><title>Window 2</title></head>");
win.document.write("<body><h3 align=center>Window One</h3>");
win.document.write("</body></html>");}

//-->
</script>
</head>
<body>
<form action="#">
<input type="submit" name="mywin" value="Create Window!"
onclick="MakeA Win()" />
</form>
</body>
</html>

glenngv
03-22-2005, 10:25 AM
Did you really follow all the suggestions? :rolleyes:

If you remove the space in the function name and the newline between "directories=yes" and ",status=yes", it will work.

To debug, open the Tools->Javascript Console to see javascript errors. That will tell you the exact error and will help you fix it.

sunzini
03-22-2005, 10:33 AM
It works's that's great!

I must have given you the original version.

Because i tried it with the changes and it still didn't work. It must be my browser or somthing.

thanks for the help, it's appreciated

glenngv
03-22-2005, 10:39 AM
Or it must be the user, j/k :D

In the future, use the Javascript console to fix errors.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum