That's possible, but you'll have to take care of passing the right
context everytime:

//main page
<script type="text/javascript" src="jquery.js"></script>

//inside the iframe
<script>
$ = jQuery = $('iframe')[0].parent.jQuery;
$('#myElement', document); //pass the iframe's document as context
</script>

to exemplify, if you were to do this "from the outside":

//main page
var iframe = $('iframe')[0];
iframe.contentWindow.$ = iframe.contentWindow.jQuery = jQuery;
iframe.contentWindow.$('.iframe_element', iframe.contentDocument);
//jquery will search in the context of the document it was loaded in,
if you don't specify one

the practical way to do that would be to save the iframe's document in
an object and always start from there:

var $iframe = $( $('iframe')[0].contentDocument );
$iframe.find('#iframe_element');
$iframe.find('.another_element');

There are probably other caveats for this use of jQuery, it depends on
the complexity of what you're doing.

cheers,
- ricardo

On Mar 2, 5:42 pm, jojobar <skdu...@gmail.com> wrote:
> Hi!
>
> I am exploring different options to write a new program and would like
> to get some ideas from the group is this way of doing things makes
> sense...
>
> I have a main page and an iframe inside that page. We want to keep the
> iframe code very small (because this is a ssl page and javascript wont
> cache), so my idea is to load the jquery_ver.js on the main page but
> use all jquery functions from inside the pages in the iframe.
>
> This is because the top page will be loaded only once (with menus
> etc.) and will not have impact on performance with lots of
> javascripts.
>
> Is this possible. I am still learning jquery and tried a few things
> but it won't work.
>
> Thanks
> jb

Reply via email to