惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Blog — PlanetScale
Blog — PlanetScale
SecWiki News
SecWiki News
Google DeepMind News
Google DeepMind News
WordPress大学
WordPress大学
小众软件
小众软件
C
CERT Recently Published Vulnerability Notes
Jina AI
Jina AI
N
Netflix TechBlog - Medium
GbyAI
GbyAI
IT之家
IT之家
Apple Machine Learning Research
Apple Machine Learning Research
AWS News Blog
AWS News Blog
G
GRAHAM CLULEY
L
Lohrmann on Cybersecurity
C
Cybersecurity and Infrastructure Security Agency CISA
I
Intezer
T
Tor Project blog
P
Palo Alto Networks Blog
P
Privacy & Cybersecurity Law Blog
P
Privacy International News Feed
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
P
Proofpoint News Feed
T
Tailwind CSS Blog
C
Check Point Blog
Cloudbric
Cloudbric
Y
Y Combinator Blog
The Last Watchdog
The Last Watchdog
Forbes - Security
Forbes - Security
Last Week in AI
Last Week in AI
S
Security Affairs
博客园 - Franky
F
Fortinet All Blogs
量子位
M
MIT News - Artificial intelligence
C
Cisco Blogs
酷 壳 – CoolShell
酷 壳 – CoolShell
Stack Overflow Blog
Stack Overflow Blog
S
Secure Thoughts
V
Visual Studio Blog
AI
AI
美团技术团队
B
Blog RSS Feed
Application and Cybersecurity Blog
Application and Cybersecurity Blog
博客园 - 三生石上(FineUI控件)
阮一峰的网络日志
阮一峰的网络日志
Engineering at Meta
Engineering at Meta
人人都是产品经理
人人都是产品经理
Microsoft Security Blog
Microsoft Security Blog
T
Threatpost
Cyberwarzone
Cyberwarzone

轶哥博客

blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog
blog
轶哥 · 2020-08-25 · via 轶哥博客

iframe控制显示范围,显示目标网页的特定区域,这对于特定场景非常有用,是一种简单高效的系统整合方案。

在新版本的浏览器中,vspacehspace已经失效了。因此iframe显示特定内容只能采取嵌套iframe的方案。

例如,控制iframe仅显示https://www.wyr.me的头像部分。

第一层iframe负责控制页面left、top

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>轶哥</title>
</head>

<body>
  <iframe src="https://www.wyr.me/" frameborder="0" scrolling="no"
    style="position: absolute;top: -190px;left: -40px;height: 405px; width: 1024px;"></iframe>
</body>

</html>

其中,width相当于是屏幕宽度,影响响应式页面的呈现方式。需要呈现的内容,放置于页面左上角。效果如下:

iframe1.png

第二层iframe负责控制显示宽度、高度

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>轶哥</title>
</head>

<body style="background-color: #888">
  <iframe src="iframe1.html" frameborder="0" scrolling="no"
    style="position: absolute;top: 0px;left: 0px;height: 215px; width: 215px;"></iframe>
</body>

</html>

在第二层iframe中,只需要控制宽高即可实现对特定区域的显示。

iframe2.png

总结

嵌套多层iframe来显示特定区域几乎是目前唯一可行的方案。该方案也存在弊端,手机和PC可能显示效果不一致。

收藏本站,改天我们聊聊跨域下iframe通讯。