views:

61

answers:

4

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

A: 

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

$(".reloadAds").click(function() {
        jQuery.each($("iframe"), function() {
            $(this).attr({
                src: $(this).attr("src")
            });
        });
        return false;
    });
fehays
yes but the problem is that when i press the refresh button, because of the reason that the url doesnt change it loads again the src which is the home page of the site of the iframe...
Xara
A: 

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.

Kau-Boy
I ve tried also this but it doesnt do it
Xara
A: 

Try the following:

var iframe = document.getElementById('your-iframe');
iframe.src = iframe.src;
elusive
A: 

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.com/jquery-latest.js"&gt;&lt;/script&gt;
  <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.com';
      } )
    );

    $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.com"&gt;&lt;/iframe&gt;

</body>
</html>
Peter Bailey
Hello and thank you for your time!
Xara
I tried the code that you wrote, but i think that the iframe doesnt reloads again. Your code also has the same problem as mine. When i press the back button, i want only to go back to the iframe. So when the history of the iframe ends, it goes back of the main page. I googled it and i found a hash function stg like that. It doesnt work on me because of the not url changing
Xara
That's not possible. The `history` object has a `length` property, but there's no way to determine where in the history you currently are, which would be required information to perform such a task. And the refresh *does* work.
Peter Bailey
Yes thank you it works. I had done a mistake. But i didnt understand stg about the history you are writting. Sorry my english is pure. I mean that i dont want the back button to goes back when the history of the iframe ends.
Xara
When the history of the frame "ends" - the back button does nothing. But you can't determine that you're at the end of the history.
Peter Bailey