views:

216

answers:

7

the window.open() object has some funky parameter list...

is there a way to do something like window.open({options..});

Thoughts?

+1  A: 

No. That is a dom function called with javascript.

In any case, the 'options object' strategy is really only coming into such great usage with the concept of JSON, which the DOM spec preceeds by some time.

You can build a JS object with fields for the parameters and override toString() if you want a window opener helper.

Sky Sanders
+1  A: 

You could pass options as a URL parameter:

window.open( myURL + "/?options=" + JSON.stringify(options) );
Justin Ethier
Why the downvote? :(
Justin Ethier
You're misunderstanding the question.
SLaks
Can you be more specific?
Justin Ethier
+2  A: 

There is no such facility built-in to the language.

However, it's fairly easy to write one yourself.
For example:

function popup(url, name, options) {
    if (arguments.length === 2) {
        options = name;
        name = options.name;
    }

    var features = false;

    for (var key in options) {
        if (!options.hasOwnProperty(key)) continue;
        if (key === "name") continue;

        if(features)
            features += ",";

        features += key + "=";

        if (!options[key])
            features += "no";
        else if (options[key] === true)
            features += "yes";
        else
            features += options[key];
    }
    return window.open(url, name, features);
}
SLaks
example not coming soon enough i am afraid. lol.... 10 answers in 3 minutes.
Sky Sanders
+2  A: 

well

function newWindow(options) {
  var opts = [], keys = ['height', 'width', 'scrollable', /* all those options */];
  for (var i = 0; i < keys.length; ++i) {
    if (keys[i] in options)
      opts.push(keys[i] + '=' + options[keys[i]]);
  }
  return window.open(options.url, options.name, opts.join(','));
}
Pointy
+1 That is certainly one way to giterdone.
Sky Sanders
It would be cleaner to allow `yes` or `no` strings to be specified as booleans.
SLaks
Yes I guess so; it was just a suggested approach.
Pointy
+1  A: 

No, but you could write your own wrapper easily enough.

Skilldrick
+1  A: 

I don't think so as the features are a comma separated list of window features

From MDC

var WindowObjectReference = window.open(strUrl, 
                                        strWindowName  
                                        [, strWindowFeatures]);

There's nothing stopping you from writing a wrapper though that accepts an object and then calls window.open() with the appropriate arguments

Russ Cam
+1  A: 

you could make your own function to parse a JSON object and call the window.open() function with specific params based on the parsing?

ocdcoder