views:

250

answers:

6

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 something like window.open? Is it compatible in IE also? Or should I use something in Jquery?

Thanks in advance.

+2  A: 

Creating a New Window with JavaScript (includes window size)
http://www.fontstuff.com/frontpage/fptut06.htm

Robert Harvey
A: 

JavaScript is the best way of doing this

var win = window.open(cant remeber this bit); win.resizeTo(w, h); win.focus();

Jonathan D
A: 

window.open (URL, windowName[, windowFeatures])

More infos here

MaxiWheat
A: 
winRef = window.open( URL, name [ , features [, replace ] ] )

source: http://www.javascripter.net/faq/openinga.htm

Juraj Blahunka
A: 
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.

Daren Schwenke
+2  A: 

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.

Jason Berry
This is a nice approach. I guess I'm lucky that all my commercial stuff is for a controlled group of users, who all have javascript enabled. :) With the this.href bit too, you could set this with a Jquery selector and instead of an id affect an entire class of objects.
Daren Schwenke
Exactly. One use of this method is to add a rel="external" on any link you want to have opened in a new window and use JavaScript (or whatever JavaScript library of choice you like) to open them in a new window like this.
Jason Berry