Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1314
  • Last Modified:

Reload specific iframes using jQuery

Hello Experts,

I have several iframes placed within a page.
I hide and show the iframes depending on whether the user is logged in or not.
Currently, when they log in - I show all the 'logged in' specific iframes
and hide all the 'not logged in' specific iframes (and vice versa).

However, I need all the 'logged in' iframes to reload as they show new details as soon as the user logs in.
If I have
<iframe id='iframe1-in' src='a.php' />
<iframe id='iframe1-not' src='a1.php' />
<iframe id='iframe2-in' src='b.php' />
<iframe id='iframe2-not' src='b1.php' />

How can I force iframe1-in and iframe2-in to reload their respective src files?

Thanks!
0
jagku
Asked:
jagku
2 Solutions
 
h4miCommented:
$('#iframe').each(function() {
 this.contentWindow.location.reload(true);
});
0
 
BardobraveCommented:
I always strongly recommend not to use iframes into any webpage.

Iframes are deprecated by W3C and it's use probably won't be supported in a near future by browsers.

However, to answer your question. I supose you can force a reload of the file reloading the own iframe object, so something like:

getElementById("iframe1-in").contentDocument.location.reload(true);

should work.
0
 
JosephEricDavisCommented:
You should just be able to use jQuery to reset the src attribute on the tag.

Take a peek at the html doc below.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Untitled Page</title>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
    <script type="text/javascript">
        $(function () {
            $('#btnRefresh').click(function () {
                $('#testFrame').attr('src', 'http://www.kc-soccer.com');
                return false;
            });
        });
    </script>
</head>
<body>
    <input id="btnRefresh" type="button" value="Refresh" />
    <iframe id="testFrame" src="http://www.kc-soccer.com" />
</body>
</html>

Open in new window

0
 
jagkuAuthor Commented:
Hi,

Many Thanks.
I have marked the first one as the best solution - because this is the first response I got. The other one also works.

Bardobrave - you mention iframes have been deprecated by W3C. When was is deprecated?
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now