View Full Version : open a new window by A LINK
joonstar
10-12-2004, 08:07 AM
<script language="javascript">
<!--
function OpenWindow(url,intWidth,intHeight) {
window.open(url, "_blank", "width="+intWidth+",height="+intHeight+",resizable=1,scrollbars=1") ;
}
//-->
</script>
<input type=button value="NEW" onClick="javascript:window.open('new.htm','_blank','width=500,height=400')">
If a user clicks the input type button, it will open a new window.
I like to open a new window by A LINK, not input type button.
The following is one of my trial code which is failed.
trial code
<a href="new.htm" onClick="javascript:window.open()" target="_blank" 'width='500' height='400'>NEW</a>
The above trial code opens two windows, one is blank, and the other is correct url window with tool bars.
I need only one new window, and I like to remove tool bars .
Can I do it with your help?
Thanks in Advance
glenngv
10-12-2004, 08:15 AM
<a href="new.htm" target="_blank" onclick="window.open(this.href, this.target, 'width=500, height=400');return false;">NEW</a>
The href and target attributes are there for javascript disabled browsers.
joonstar
10-12-2004, 08:27 AM
Thank you
joonstar
10-12-2004, 08:34 AM
<a href="new.htm" target="_blank" onclick="window.open(this.href, this.target, 'width=500, height=400');return false;">NEW</a>
The size of the new window is 500*400.
It's good because It's what I expected.
But I can't make the window to maximize.
Can I control the basic size of the new window with making the new window to maximize, and back to the basic size possible?
glenngv
10-12-2004, 09:25 AM
window.open(this.href, this.target, 'width=500, height=400, resizable=1')
Any unspecified window feature means it is off, if you list it without specifying 1/0 (or yes/no), it is enabled by default. So you can also say 'width=500, height=400, resizable'.
Here's more info on window.open method.
http://www.devguru.com/Technologies/ecmascript/quickref/win_open.html
jamescover
10-12-2004, 11:45 AM
From DevGuru:
myWindow = window.open("", "tinyWindow", 'toolbar,width=150,height=100')
myWindow.document.write("Welcome to this new window!")
myWindow.document.bgColor="lightblue"
myWindow.document.close()
Is the above correct?
or should it be:
var myWindow = window.open("","","");
myWindow.document.open();
myWindow.document.write("whatever");
myWindow.document.close();
Just opening the window, doesn't open the document data stream for writing, right!?!? I mean, obviously, it does, or it wouldn't work, but isn't the second method preferred, or is it redundant? Inquiring minds want to know... :eek:
-james
glenngv
10-12-2004, 03:27 PM
Also from DevGuru.
In general, it is not necessary to open the document using the document.open method, since the document.write method will automatically open the file and discard (erase) the contents. However, after the write is complete, you need to close the document by using the document.close method.
--- http://www.devguru.com/Technologies/ecmascript/quickref/doc_write.html
jamescover
10-13-2004, 12:18 AM
...I was asking for a higher authority/reference. But I found it . The reason I was asking is because there are a lot of things you [b]can do, but shouldn't, like not closing the document stream, you don't have to, but should.
Gecko DOM Reference:
If a document exists in the target, this method clears it. Also, an automatic document.open() is executed if document.write() is called after the page has loaded.
Makes, sense, in the context of loading a new blank page/document.
Just shortened my code by one line :thumbsup:
Thanks.
-james
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.