views:

124

answers:

3

Hi all,

I've got a question about CSS based popup windows, like those generated by jQuery UI's dialog system, or Colorbox. If I use those (or something like them) to open a popup window to an HTML page and that page has Javascript in it, does the Javascript in the popup window run in its own context, or does it become part of the context of the Javascript in the parent window that opened it? I ask so that I can write the Javascript on both pages (parent and popup) so there is no namespace collision.

Thanks in advance! Doug

+1  A: 

That depends on the type of popup. (I'm assuming we are talking about in-page popups here and not window.open() ones that open a new browser window.)

If it contains an IFRAME in which you load a separate page, then that page will have its own styles. You will have to re-load any CSS and JavaScript files you need.

If it doesn't contain an IFRAME, but just a regular DIV or other element into which content is loaded through AJAX (or directly output in the "parent" HTML page) then the popup will run in the context of the parent page.

Pekka
You've got what I'm talking about, this would be in-page popup, not a windows.open() style. Since I'm using Colorbox to open the popup, and setting iFrame to true, sounds like that makes the Javascript in the popup run in its own context.Thanks!
writes_on
@writes_on you can easily find out by right-clicking the popup contents in Firefox. If you get a menu item saying "this frame >", then you're in an IFrame.
Pekka
+1  A: 

If you use real popups (new windows) it is definitly in its own context.

If you use modal windows purely in HTML it depends. It can be an iframe (own context) or injected elements (parent context).

neo
+1  A: 

With Colorbox, you can set the iframe property to true and it will load the content in an iframe. This gives the page its own scope. If you don't use an iframe, then the page will be loaded in the context of the current document.

$('a.someLink').colorbox({ href:"somePage.html", iframe: true });
Michael Dean
That's exactly what I'm doing, and from what you're saying this is like having a completely independent page (kind of like window.open() would provide). And this would mean my popup Javascript would be running in its own context.Thanks!
writes_on