1

Yet another cross-domain iFrame question! I've search everywhere and believe this is impossible, so here goes:

The scrollbars of an iframe are part of that iframe's window element, so because of the same origin policy I can't directly style them. At first I thought I'd be clever and create a scrollable DIV using jQuery UI draggable event within a "track" container. I setup a dummy scrollbar and everything was working, excepting being able to scroll the iframe... again because of the same origin problem.

So..

  1. Is there a way to style an iframe's scrollbars if the iframe content is from a different domain?

OR

  1. Is there a way to scroll an iframe if the iframe content is from a different domain?

Thanks!

Aaron
  • 2,482
  • 1
  • 26
  • 56
  • 1
    I think the answer is no for both. You can't access or manipulate content from another domain. – Gabriel Santos Aug 25 '12 at 00:35
  • 1
    One might want to consider there are actually a lot of users who consider scrollbars to be part of THEIR computer/software/browsing-interface/theme and don't like someone else re-styling it. _Just an opinion._ _@Gabriel Santos:_ Well.. if you REALLY want to.. you can access and manipulate content from another domain. Use a proxy on your own domain to fetch their data, or even simpler, use [yql](http://stackoverflow.com/a/12080097/588079). Then you only need to present their data inside YOUR iframe. There are also 'controlled' 'techniques' (if you control both domains) like easyXDM.net – GitaarLAB Aug 25 '12 at 02:54
  • Just found out about new attributes added to iframe in html5, one of which removes same origin policy restrictions. Only supported in webkit – Aaron Aug 25 '12 at 16:22

1 Answers1

2

Assuming you can figure out the size of the site somehow, you could set the size of the iframe to that content's size...

<html>
<body>
<div style="width:400px; height:400px; overflow:scroll">
    <iframe src="http://www.w3schools.com/" style="width:1000; height:1300"></iframe>
</div>
</body>
</html>

Of course, then you need to figure out the size of the site periodically...

Nick Rippe
  • 6,465
  • 14
  • 30
  • 1
    This worked perfectly by using postmessage to send the iframe doc dimensions to the site, then calculate then on resize :) – Aaron Aug 30 '12 at 15:30