writes_on
writes_on

Reputation: 1885

Javascript and CSS Popups

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

Upvotes: 0

Views: 419

Answers (3)

Michael Dean
Michael Dean

Reputation: 1576

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 });

Upvotes: 1

neo
neo

Reputation: 1270

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).

Upvotes: 1

Pekka
Pekka

Reputation: 449783

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.

Upvotes: 1

Related Questions