我目前正在致力於一個網站,該網站必須通過使用iframe從其他網站下載內容。有什麼方法可以裁剪下載的頁面的內容,只在我的網站上顯示該頁面的一部分?如何裁剪Iframe的內容以顯示頁面的一部分?
10
A
回答
26
有沒有什麼辦法可以裁剪下載頁面的內容,只顯示我網站上該頁面的一部分?
否。同源策略可以防止您以任何方式操縱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內滾動的影響。
0
在iframe中你不能做到這一點......但如果你使用的HttpWebRequest/WebResponse的那麼它很簡單......
http://www.codeproject.com/KB/IP/httpwebrequest_response.aspx
http://htmlagilitypack.codeplex.com/
這包是非常重要的......你可以通過ID讀取特定的div/span ...
4
<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]
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
此代碼爲我工作...調整邊距並保留任何最適合您的值,並將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>