I would like to open a new window with height of 600px and width of 200px, after clicking on a hyperlink.
How can I do that in HTML/Javascript?
Do I use some
winRef = window.open( URL, name [ , features [, replace ] ] )
source: http://www.javascripter.net/faq/openinga.htm
JavaScript is the best way of doing this
var win = window.open(cant remeber this bit); win.resizeTo(w, h); win.focus();
Creating a New Window with JavaScript (includes window size)
http://www.fontstuff.com/frontpage/fptut06.htm
window.open (URL, windowName[, windowFeatures])
More infos here
var user_window=window.open('http://www.someplace.com','someplace_window_name','toolbar=no,directories=no,location=no,status=yes,menubar=no,resizable=yes,scrollbars=yes,width=1024,height=768');
user_window.focus();
A user click should initiate this, or it will be blocked by most popup blockers. This works in all browsers I've had to support including IE6+, FF, Opera, Safari.
The focus bit ensures that the new window is brought to the front.
As an alternative to a popup window, I'd suggest the Dialog plugin for Jquery.
That's what I replaced 90% of my popup windows with.
Your popup becomes a popover (bound within the original window), and this as far as I can tell is never blocked by a popup blocker. The Dialog plugin allows dragable popovers, appearance and disappear effects, and lots of other cool stuff.
It's far better to attach this to the hyperlink unobtrusively, similar to:
HTML
<a href="mypopup.htm" id="popup">This will open in a new window</a>
JavaScript
window.onload = function() {
document.getElementById("popup").onclick = function(){
return !window.open(this.href, "pop", "width=200,height=600");
}
}
The benefit of this approach is that you only have to specify the hyperlink in your HTML, and if JavaScript is disabled or produces an error for some reason then it will fallback to just using a standard hyperlink.