iframe仅显示页面的某一部分 [英] iframe to Only Show a Certain Part of the Page

查看:821
本文介绍了iframe仅显示页面的某一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用iframe,我需要在宽度为300px,高度为150px的iframe中显示页面的某个部分(例如右上角)。

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.

示例:

假设我想将 iframe /portfolio.php ,但将iframe的大小设置为只在右上角上显示投资组合 - 体育部分。

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.

如何实现这个?

谢谢。

strong> EDIT : DEMO

EDIT : DEMO

[感谢Pointy]

[ Thanks to Pointy ]

推荐答案

< iframe> 你一个完整的窗口工作。要做你想要的最直接的方法是让你的服务器给你一个完整的页面,只包含你想要显示的片段。

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.

只需使用一个简单的< div> ,并使用jQueryload函数加载整个页面,并只截取你想要的部分:

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.

这篇关于iframe仅显示页面的某一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆