Click to See Complete Forum and Search --> : open a new window using a button


swstos
02-05-2003, 07:08 PM
hi... I have a button in which when i click on it, links in another web page in the same folder

i did something similar using the code below:

<a href ="shape.asp" target = "window2"> link </a>

but is not a button its just a link...

how can i do it using a button??? and also how can i choose what will be the width and the height of the new window???

i think it is very simple what i am asking, but since i am a newbie i need your help..

Thanks in advance

Sergey Smirnov
02-05-2003, 07:20 PM
<form>
<input type=button
onclick="document.location.href='shape.asp'"
value="Click and Go">
</form>

swstos
02-05-2003, 07:24 PM
How can i define the width and height of the new window???

Thanks alot for the help...

Charles
02-05-2003, 07:31 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<title>Example</title>
<form action="http://www.bettiepage.com/images/photos/whip/whip7.jpg" target="child" onsubmit="window.open(this.action, 'child', 'height=300,width=200'); return false">
<div><input type="submit" value="Submit !"></div>
</form>

Sergey Smirnov
02-05-2003, 07:31 PM
Using above approach your are unable to resize child page from the parent one, but you able to put the following script into the head of the child page:

<script>
window.resizeTo(w,h);
</script>

where w and h are the width and height of the window.

However, if you want to change the other window options such as hide toolbar, it is better to use window.open, instead of window.location.href

swstos
02-05-2003, 07:35 PM
with the code below opens the other web page in the same window not in a new window...

<form>
<input type=button
onclick="document.location.href='shape.asp'"
value="Click and Go">
</form>

thanks for the help.

Charles
02-05-2003, 07:37 PM
I think that you will find that the method that I've posted above does exactly what you want.

Dan Drillich
02-05-2003, 07:41 PM
You can also try -


<script>
function newWin() {

var new_window = window.open("http://www.iwon.com","html_name","width=200,height=200");

}
</script>


<form>
<input type="button" onclick="newWin();" value="Click and Go">
</form>

Sergey Smirnov
02-05-2003, 07:42 PM
Opss! Sorry I missed keyword 'new'.

Actually, Dan Drillich and Charles already provided solutions.

swstos
02-05-2003, 07:43 PM
thanks people you are all very helpful... thanks

Charles
02-05-2003, 07:46 PM
Note that the method suggested by Dan Drillich employ's invalid HTML and will leave you with a button that does nothing at all about 10% of the time.

Dan Drillich
02-05-2003, 08:14 PM
Charles,

Can you please be kind enough to explain why my solution is not perfect? :(

Thanks a lot,
Dan

Sergey Smirnov
02-05-2003, 08:22 PM
I am interested too, btw.

Charles, would you might to explain you position regarding HTML standards. May be, it better to open a new thread for this discussion.

P.S. May be You can say more than your signature said

Charles
02-05-2003, 08:46 PM
As to the invalid HTML:From the HTML 4.01 DTD:
<!ELEMENT FORM - - (%block;|SCRIPT)+ -(FORM) -- interactive form -->
<!ATTLIST FORM
%attrs; -- %coreattrs, %i18n, %events --
action %URI; #REQUIRED -- server-side form handler --
method (GET|POST) GET -- HTTP method used to submit the form--
enctype %ContentType; "application/x-www-form-urlencoded"
accept %ContentTypes; #IMPLIED -- list of MIME types for file upload --
name CDATA #IMPLIED -- name of form for scripting --
onsubmit %Script; #IMPLIED -- the form was submitted --
onreset %Script; #IMPLIED -- the form was reset --
accept-charset %Charsets; #IMPLIED -- list of supported charsets --
>Which is to say that the FORM element must contain a block level element and an ACTION attribute.

As to Mr. Drillich's method failing 10% of the time, see http://www.thecounter.com/stats/2002/November/javas.php.

As to my method working that other 10% as well, note that if you remove the onsubmit handler the image will still open in a new window, only not with your desired geometry. And even if the browser doesn't allow new windows, the image will open in the parent window; not exactly what you wanted but it sure beats nothing.

Dan Drillich
02-05-2003, 09:15 PM
Thanks Charles!