Refresh button for an iframe jquery or javascript - Stack Overflow

admin2025-04-26  2

Hello i have a problem. I have a page in which i have inside an iframe. In the parent page (not in the iframe), i want to build the browser buttons back, fw, refresh and home page. The back, fw, home page buttons are almost ok. The refresh button doesnt work. The code is below:

<a href="javascript:;" onClick="parent.document.getElementById('my_frame').location.reload();">

I also have to tell that my url is not changing i mean i have used post method and the url is always the same. Any answers of jquery or javascript???

Thanks in advence, i m really desperate

Hello i have a problem. I have a page in which i have inside an iframe. In the parent page (not in the iframe), i want to build the browser buttons back, fw, refresh and home page. The back, fw, home page buttons are almost ok. The refresh button doesnt work. The code is below:

<a href="javascript:;" onClick="parent.document.getElementById('my_frame').location.reload();">

I also have to tell that my url is not changing i mean i have used post method and the url is always the same. Any answers of jquery or javascript???

Thanks in advence, i m really desperate

Share Improve this question edited Sep 9, 2010 at 17:13 2ndkauboy 9,4033 gold badges34 silver badges67 bronze badges asked Sep 9, 2010 at 17:10 XaraXara 212 silver badges6 bronze badges 2
  • <a href="javascript:;" onClick="parent.document.getElementById('skata').location.reload();"> – Xara Commented Sep 9, 2010 at 17:15
  • Just add 4 spaces before any code and don't paste the code in an answer (as you did before) OR ment! – 2ndkauboy Commented Sep 9, 2010 at 17:20
Add a ment  | 

4 Answers 4

Reset to default 3

Ok, let's cover some ground rules first

  1. To get access to a frame's window object, go through the frames collection.
  2. Give your frame a name
  3. If parts of your UI don't work without javascript enabled, then don't put them in the markup - add them with javascript
  4. Don't use anchor elements for controls that aren't hyperlinks

In practice:

<html>
<head>
  <title>Test Page</title>

  <style type="text/css">
    #toolbar button {
      cursor: pointer;  
    }
  </style>

  <script src="http://code.jquery./jquery-latest.js"></script>
  <script type="text/javascript">  

  $(function()
  {
    var $iframe  = $( '#my_frame' );
    var $toolbar = $( '<div/>' ).attr( 'id', 'toolbar' );
    var frame    = self.frames['my_frame'];

    $toolbar.append(
      $('<button/>')
      .text( 'Home' )
      .click( function( event )
      {
        event.preventDefault();
        frame.location.href = 'http://www.google.';
      } )
    );

    $toolbar.append(
      $('<button/>')
      .text( 'Back' )
      .click( function( event )
      {
        event.preventDefault();
        history.back();
      } )
    );

    $toolbar.append(
      $('<button/>')
      .text( 'Forward' )
      .click( function( event )
      {
        event.preventDefault();
        frame.history.forward();
      } )
    );

    $toolbar.append(
      $('<button/>')
      .text( 'Refresh' )
      .click( function( event )
      {
        event.preventDefault();
        frame.location.reload();
      } )
    );

    $toolbar.insertBefore( $iframe );

  } );

  </script>
</head>

<body>

  <iframe id="my_frame" name="my_frame" width="400" height="300" src="http://www.google."></iframe>

</body>
</html>

Have you tried this: http://www.byronsorrells./web-development/reloading-an-iframe-with-jquery/

$(".reloadAds").click(function() {
        jQuery.each($("iframe"), function() {
            $(this).attr({
                src: $(this).attr("src")
            });
        });
        return false;
    });

Why don't you do it like this:

<a href="javascript:document.getElementById('my_frame').location.reload();">

You don't need a onclick if you already have a href with no other target.

Try the following:

var iframe = document.getElementById('your-iframe');
iframe.src = iframe.src;
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1745603378a309439.html

最新回复(0)