Jordy
Jordy

Reputation: 4809

Return value from PopUp to parent

I have a difficult question and don't know if this is possible:

I have a link on my parent window that opens a popup with a webpage: forum.website.com. This webpage is a page with a forum where an user can post a new topic. He type the subject and the content, and submits the topic. The url is now: forum.website.com?board=1&topic=X where the X is the unique id. Now this ID should be sent to the parent window, so it knows the id of the new generated topic. How can I do this with javascript?

Thanks!

Upvotes: 0

Views: 1144

Answers (2)

Cerbrus
Cerbrus

Reputation: 72849

Parent / source window code:

var storedData;
function setData(id){
    storedData = id;
}

Popup code:

function topicPosted(id){
    opener.setData(id);
    // Do stuff
}

When you close a popup in IE, the data assigned to the opener's object by the popup is lost. That's why you need to call a function from from the popup to the opener, with the data as parameters. The function then sets (copies) the data to variables in the opener. If it weren't for IE, you might have simply done this:

function topicPosted(id){
    opener.storedData = id;
    // Do stuff
}

Upvotes: 2

mram888
mram888

Reputation: 5139

Use sessionStorage for solving this:

http://www.nczonline.net/blog/2009/07/21/introduction-to-sessionstorage/

Upvotes: 4

Related Questions