views:

48

answers:

1

Hello my problem is that whenever i load content to an iframe through javascript and jquery it only loads the first time and then i cannot load anything over it. the function I use is this:

function loadContent(elementSelector, sourceURL) {
    $(""+elementSelector+"").attr('src', sourceURL );
}

and i call it through

<li><span><a href="javascript:loadContent('#oPanel', 'http://www.google.com');"&gt;Google&lt;/a&gt;&lt;/span&gt;&lt;/li&gt;

Am I doing something wrong? Thanks!

+1  A: 

I've tried to reproduce your problem, but I was not able to. I've create a very simple site with to links and one iframe:

​<a class="iframe" href="http://microsoft.com"&gt;Microsoft&lt;/a&gt;
<a class="iframe" href="http://google.com"&gt;Google&lt;/a&gt;
<iframe id="oPanel"></iframe>

and 4 lines of unobstrusive JavaScript to load those links within the iFrame:

​$('a').click(function(){
    $('#oPanel').attr('src',$(this).attr('href'));
    return false;
});​​​​​

And it's working as expected. You can try it here: http://jsfiddle.net/jQncy/

jigfox