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

推荐订阅源

V
Visual Studio Blog
Recent Announcements
Recent Announcements
有赞技术团队
有赞技术团队
The GitHub Blog
The GitHub Blog
N
Netflix TechBlog - Medium
腾讯CDC
A
About on SuperTechFans
博客园 - 叶小钗
大猫的无限游戏
大猫的无限游戏
小众软件
小众软件
D
DataBreaches.Net
D
Docker
宝玉的分享
宝玉的分享
量子位
Microsoft Azure Blog
Microsoft Azure Blog
Martin Fowler
Martin Fowler
博客园 - 三生石上(FineUI控件)
Jina AI
Jina AI
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
V
V2EX
Last Week in AI
Last Week in AI
H
Help Net Security
Hugging Face - Blog
Hugging Face - Blog
M
MIT News - Artificial intelligence

轶哥博客

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通讯。