如何裁剪Iframe的内容以显示页面的一部分?

问题描述 投票:13回答:5

我目前正在开发一个必须通过使用iframe从其他网站下载内容的网站。有什么办法可以裁剪下载页面的内容,只显示我网站上该页面的一部分吗?

asp.net html iframe
5个回答
29
投票

有什么办法可以裁剪下载页面的内容,只显示我网站上该页面的一部分吗?

不会。同源策略会阻止您以任何方式操纵iframe,包括滚动位置。

iframe放入一个具有定义高度和宽度的div容器,并使用overflow: hidden剪切视口,将有一种解决方法:

<div style="width: 500px; height: 500px; overflow: hidden">

并给iframe一个相对位置:

<iframe src="..." style="position: relative; left: -100px; top: -100px">

这样,您可以调整页面上可见的iframe部分。但是,整个页面仍然会被渲染,这种方法不能免受像iframe内部滚动这样的影响。


6
投票
<div style="position: absolute; left: 0px; top: 0px; border: solid 2px #555; width:594px; height:332px;">
<div style="overflow: hidden; margin-top: -100px; margin-left: -25px;">
</div>
<iframe src="http://www.centricle.com/tools/html-entities/" scrolling="no" style="height: 490px; border: 0px none; width: 619px; margin-top: -60px; margin-left: -24px; ">
</iframe>
</div>
</div>

这段代码对我有用。

来源[http://extechbuzz.blogspot.com/2012/12/iframe-how-to-display-specific-part-of.html]


1
投票

在iframe你不能这样做......但如果你使用HTTPWebRequest / WebResponse那么它非常简单......

http://www.codeproject.com/KB/IP/httpwebrequest_response.aspx

http://htmlagilitypack.codeplex.com/

这个包很重要......你可以通过id读取特定的div / span ...


0
投票

要裁掉嵌入式page底部的广告,我使用了以下内容:

<div style="width: 1000px; height: 390px; overflow: hidden">
<iframe src="https://openflights.org/user/dankohn1" width="1000"
height="600" style="border:none" scrolling="no">
</iframe></div>

0
投票

这段代码对我有用...将margin-top和margin-left调整为适合你的最佳值,并将iframe的高度和宽度调整为你想要的任何值。

<html>
<div style="overflow: hidden; margin-top: -1440px; margin-left:0;">
<iframe src="https://fiitjeelogin.com/StartPage.aspx" scrolling="no" height="1550"width="300" frameBorder="0">
</iframe>
</div>
</html>
© www.soinside.com 2019 - 2024. All rights reserved.