1

i can't make this code work, the iframe should scroll down to the bottom automatically when the iframe is refreshed.

FIDDLE

CODE:

<html>
<!--
  Created using jsbin.com
  Source can be edited via http://jsbin.com/ujuci5/2/edit
-->
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
</head>
<body>
  <p>iframe:</p>
  <iframe src="http://jsbin.com/aloko5" id="frame" frameborder="0" width="200px" height="300px"></iframe>
<script>
$(window).load(function ()
{
  var $contents = $('#frame').contents();
  $contents.scrollTop($contents.height());
});
</script>

</body>
</html>​

cn anyone help me with this, i'm kinda stuck

Blender
  • 289,723
  • 53
  • 439
  • 496
telexper
  • 2,381
  • 8
  • 37
  • 66
  • Your fiddle says it should use MooTools. But your code invokes jQuery. Is the setting on your fiddle wrong? – Jonathan M Sep 30 '12 at 03:58
  • 1
    You can't modify the frame: *Unsafe JavaScript attempt to access frame with URL http://jsbin.com/aloko5 from frame with URL http://fiddle.jshell.net/_display/. Domains, protocols and ports must match.* – Blender Sep 30 '12 at 03:59
  • i tried it on my desktop still not scrolling down even if it is a safe url – telexper Sep 30 '12 at 04:05

2 Answers2

0

Do you have access to the code within the iframe? I believe you need to set the scrollTop within the iframe code itself.

For example:

$("body").scrollTop(100);

Edit: find more information here: How to get scrollTop of an iframe

Community
  • 1
  • 1
Adam Plocher
  • 13,994
  • 6
  • 46
  • 79
0

The onLoad event to be intercepted shall be the one from the iframe itself, not that from the window.

Also, the comment from Blender is, partially, valid.

This setup will work only if the document opened at the iframe belongs to the same domain as the parent document. And with the same protocol:

- http://domain/main.aspx as the container and http://domain/inner.aspx at the iframe is valid
- http://domain/main.aspx as the container and https://domain/inner.aspx at the iframe will be blocked
- http://domain/main.aspx as the container and http://another/inner.aspx at the frame will also be blocked

(sent from my PDA)

Marcus Vinicius Pompeu
  • 1,219
  • 1
  • 11
  • 24