I am creating a popup chat window that allows the users to pop the call script out of the page into its own window, so that they can keep that window up but also travel to other pages of the website. I am just grabbing the html from the call script and inserting it into the popup window. The problem is when the options are clicked, changed, whatever by the user nothing is happening bc the new window does not have the same files as its home page. I am wondering how can I wire up or transfer logic/functionality to the new window? For example I need to make an ajax call, which goes into a controller in a c# file within the project. Anyone know what I'm talking about and how to do this?
2 Answers
I am not sure I understand exactly what you are describing, but you can use localStorage or sessionStorage to use your browser to save information for you across pages. See explanation here: using localStorage in html5 and here: Storing Objects in HTML5 localStorage

- 1
- 1

- 882
- 5
- 16
- 33
One approach would be to make the popup window a "real" page, so that the popup renders the same page, just without a layout, and all of the 'logic' (I assume this means including javascript files?) will be included. No copying of HTML here, you're rendering the page on the server. I'm not familiar with C#-based frameworks/web apps, but simply passing a URL query param, like 'layout=false' is an easy way to tell your script to render a page in a "plain" layout. There are likely more elegant approaches available here. For example, in a Sinatra app (Ruby), my route could detect what type of layout to use based upon some suffix on the route. E.g. /app/chat vs. /app/chat.part ... oftentimes you do this to render JSON, vs HTML, and so forth. '.part' can be anything you want, depends on if your framework allows for this (you can always roll-your-own function to examine the request vars, not that hard).
Another approach, which I've never tried, would be to embed or inject javascript in the html that gets copied into the popup window before allowing the popup to open. Here is a SO answer related to that: Capture new browser window open event with javascript
I think there are more advanced approaches that would include some simple Javascript in the page which downloads necessary files from the server when the popup is opened, but that seems like overkill for what you described. My 2 cents is just use window.open, and use the query vars to tell the server what to render. But if you're a javascript guru, by all means, get fancy.