1

Is it possible to use jQuery in a second window on my page? I've tried something like this:

var $ = document.parent.$;

But that doesn't seem to work. Any other ideas? I can't load the framework again.

Thanks!

Colin Brock
  • 21,267
  • 9
  • 46
  • 61
kevin
  • 417
  • 4
  • 20
  • 1
    When you say use in a second window do you mean, you have a physical window being opened that you would like to have access the main window? are you talking about a frame you have loaded in the same window as the parent? Or are you talking about modular pop overs like a lightbox? – chris Feb 10 '12 at 22:53
  • Thanks, Chris. I mean that I'm using jQuery UI's Dialog to open a new window, and then from within that area, I have an iframe. The contents of that iframe, I'd like to be able to use the existing jquery framework from the parent page. Any ideas? – kevin Feb 10 '12 at 22:57

2 Answers2

1

when its in a frame or external window then the library needs to be in that HTML, even if you load() html in through a modal dialog. This is the case if your using jquery/javascript within those elements to manipulate anything outside of them. If your not and all you wish to do is do something from the main window to the child windows frame or otherwise you would have to name the windows/frames.

Reason I say this is cause the DOM is already rendered at that point. You can add javascript dynamically as well with javascript after the DOM is rendered but for the sake of ease I would go with the above mentioned, as theres no real harm calling in jquery more than ones in a scenario like this, or at least no harm I can think of at the moment

On the same note this will also be helpful for you most likely as well:

jQuery select element in parent window

Community
  • 1
  • 1
chris
  • 36,115
  • 52
  • 143
  • 252
0

have you tried var $ = window.parent.document.$; ?

MyStream
  • 2,533
  • 1
  • 16
  • 33