the window.open() object has some funky parameter list...
is there a way to do something like window.open({options..});
Thoughts?
the window.open() object has some funky parameter list...
is there a way to do something like window.open({options..});
Thoughts?
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.
You could pass options
as a URL parameter:
window.open( myURL + "/?options=" + JSON.stringify(options) );
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);
}
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(','));
}
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
you could make your own function to parse a JSON object and call the window.open() function with specific params based on the parsing?