DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Dave has posted 5 posts at DZone. View Full User Profile

Prototype-powered Popups

12.11.2008
| 4080 views |
  • submit to reddit
        taken from http://snook.ca/archives/javascript/prototypepowere/
var Popup = {
  open: function(options)
  {
    this.options = {
      url: '#',
      width: 300,
      height: 300
    }
    Object.extend(this.options, options || {});
    window.open(this.options.url, '', 'width='+this.options.width+',height='+this.options.height);
  }
}

Popup.open({url:'http://www.example.com/'});
... variation that uses the Class object.
var Popup = Class.create();
Popup.prototype = 
{
  initialize: function(options)
  {
    this.options = {
      url: '#',
      width: 300,
      height: 300
    }
    Object.extend(this.options, options || {});
    window.open(this.options.url, '', 'width='+this.options.width+',height='+this.options.height);
  }
}

new Popup({url:'http://www.yahoo.com/'});