tags:

views:

48

answers:

2

Hello,

I am working on iframes, and I need to show a certain portion of the page [say, the top right ] in an iframe with about 300px width and 150px height.

Example:

Say I wanted to put an iframe of www.mywebsite.com/portfolio.php on a page, but have the iframe sized to only show the "portfolio-sports" section at the top right.

How can I achieve this ?

Thanks.

EDIT : DEMO

[ Thanks to Pointy ]

A: 

Set the iframe to the appropriate width and height and set the scrolling attribute to "no".

If the area you want is not in the top-left portion of the page, you can scroll the content to the appropriate area. Refer to this question:

http://stackoverflow.com/questions/1192228/scrolling-an-iframe-with-javascript

I believe you'll only be able to scroll it if both pages are on the same domain.

Arctic Fire
+1  A: 

An <iframe> gives you a complete window to work with. The most direct way to do what you want is to have your server give you a complete page that only contains the fragment you want to show.

As an alternative, you could just use a simple <div> and use the jQuery "load" function to load the whole page and pluck out just the section you want:

$('#target-div').load('http://www.mywebsite.com/portfolio.php #portfolio-sports');

There may be other things you need to do, and a significant difference is that the content will become part of the main page instead of being segregated into a separate window.

Pointy
Thanks Pointy. It is just what I was looking at - "Skipped iframe".
MANnDAaR