Jump to content

Creating New Window With Variable Info


Costanza

Recommended Posts

Hi, not an error this time, I've just got a question on methodology: I want to have a user click a button which opens a new window that has info on it that was based on factors from the original page. The idea is that the user is assembling parts on the original page, then when they click this button the names of all those parts will be listed in a simple, printable format. (the info I am pulling from the first page are the title attributes of several divs) What would be the right way to go about this? As always, thank you!

Link to comment
Share on other sites

You can access the other window's document property from the same script that opened said window. So it's just a matter of copying the data from one place to another:

var newWindow = window.open(...);newWindow.document.getElementById("destinationElem").innerHTML = document.getElementById("sourceElem").title;

EDIT: On second thought, the above probably wouldn't work because the new window needs to load before being able to access it's DOM. So you might need a script in the new document to run onload that accesses the information on the main page. The idea is the same, except you'll use the opener property to access the main page:

document.getElementById("destinationElem").innerHTML = opener.document.getElementById("sourceElem").title;

Another option, would be to create the entire DOM for the new window with JavaScript. If the new document is relatively simple, this might not be a bad idea. It would save creating another file to maintain as well as eliminating problems with accessing elements before they're loaded. If the new document is complex, though, you're probably better off creating another file.

Link to comment
Share on other sites

Thanks ShadowMage, that method works! (obviously with the changes to fit my intended needs) I'm getting into a fair amount of code and methods that I've never used before so I'm still learning how it all works. Been reading a lot of the entries on this site for objects and functions but sometimes you need human help for more complex issues.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...