tags:

views:

33

answers:

4

Here is my code:

function show()
{
    var parameters = new Object(); 
    parameters.F1MBFC = 'N';
    parameters.F1MCSI = 'N';
    parameters.F1MMCY = 'N';
    parameters.F1NACD = 'B';
    parameters.F1RVCR = 'N';

    parameters.SOURCEFILED = '_fld:FACILITY7';

    showPopWin('http://mysite/popupForm.aspx', 650, 450, null);
}

How i can pass as parameter in url the object parameters? Any ideas?

A: 

You can serialize it and add it as a string to the URL and deserialize it before use.

RaYell
A: 

You could serialize your object and pass it as a get parameter.

Here is how to serialize a object in JavaScript:

var a = {
    name: "alexn",
    age: 20
};

a.toSource();

yields "({name:"alexn", age:20})"

You should be able to use the following:

showPopWin('http://mysite/popupForm.aspx?parameter=' + parameters.toSource(), 650, 450, null);
alexn
While of arguable value, it's also worth noting that this approach would yield a significant attack vector for XSS. I would avoid doing this at all costs.
Noon Silk
@silky You are absolutely right. The best thing would probably be to store this in a sesion.
alexn
A: 

As was already mentioned you can serialize the object and read in the new page. But I will just add that if you have control of the source of the opened page then you could just access the parent window from your new window to get the values you want as well.

spinon
+2  A: 

If you're actually opening the window yourself with JavaScript, then:

var win = window.open("foo");
win.document.SomeObject = "hello";

Then in the code for the other page:

alert(document.SomeObject);

You can also access the caller (depending on the browse probably) via the window.opener property. I may have got something slightly wrong but you get the general idea.

Noon Silk