如何使用 HTML 页面内的 标签创建内联框架?
front end scriptsjavascriptweb development更新于 2024/5/19 18:07:00
语法
向网页添加 iframe 的基本语法可以使用 −
下面的特定代码将在当前网页中嵌入 tutorialspoint 的 Youtube 视频。
示例
Welcome to Tutorialspoint
Creating a simple inline frame (iframe)
Document content goes here...
如上所示,使用"src"属性,我们能够将视频嵌入到网页中。除了 HTML 的全局属性之外,还有其他属性可以帮助我们创建无缝 iframe。
调整 iframe 的宽度和高度
iframe 的默认宽度为 300 CSS 像素,高度为 150 像素。为了更改这些尺寸,我们使用"width"和"height"属性。默认情况下,属性值以 CSS 像素为单位设置(除了 CSS 像素之外,百分比也可用于设置 iframe 的尺寸)。
示例
为了更好地理解这一点,让我们考虑下面的例子。
Welcome to Tutorialspoint
Creating a simple inline frame (iframe)
Document content goes here...
示例
按照示例,我们使用百分比来设置 iframe 的高度和宽度。
Welcome to Tutorialspoint
Creating a simple inline frame (iframe)
Document content goes here...
Example
CSS 样式也可用于设置 iframe 的高度和宽度。
Welcome to Tutorialspoint
Creating a simple inline frame (iframe)
Document content goes here...
去除
示例
Welcome to Tutorialspoint
Creating a simple inline frame (iframe)
Document content goes here...
示例
为了更好地理解这一点,让我们应用我们选择的边框并渲染 iframe。
Welcome to Tutorialspoint
Creating a simple inline frame (iframe)
Document content goes here...
注意 − 以前,"frameborder"属性用于设置 iframe 的边框。此属性已被弃用,并且不再受 Web 浏览器支持。
要设置在 iframe 内打开的链接,我们使用 或
您指定的链接目标属性必须引用 iframe 的名称属性(在任何给定点,两个元素的"name"和"target"的值都应该相同)。当点击具有该名称作为值的目标属性的链接时,链接的资源将在该 iframe 中打开。
示例
为了更好地理解这一点,让我们尝试一个例子 -
iframe {
width: 100%;
height: 250px;
}
Welcome to Tutorialspoint
Creating a simple inline frame (iframe)
Click here to open courses at Tutorialspoint
Document content goes here...
上面的示例显示了一个
iframe 的安全问题
尽管 iframe 已经存在很长时间并且被广泛使用,但是仍存在一些可能为攻击者打开大门的安全风险。
我们将列出使用 iframe 之前需要注意的一些安全威胁
iframe 注入
跨框架脚本
点击劫持
iframe 网络钓鱼
对话框威胁
支持 iframe 的浏览器
Web 浏览器
Google Chrome
完全支持
Edge
完全支持
Firefox支持(但如果将 iframe 元素添加到页面时被隐藏,则存在阻止 iframe 加载的错误。)
Internet Explorer
完全支持
Opera
完全支持
Safari
支持(但如果将 iframe 元素添加到页面时被隐藏,则存在阻止 iframe 加载的错误。)
移动版浏览器
Chrome Andriod
完全支持
Firefox Andriod
支持(由于错误,resize CSS 属性对此元素没有任何影响)
Opera Andriod
完全支持
Safari iOS
支持(但如果 iframe 元素在添加到页面时被隐藏,则存在阻止 iframe 加载的错误。)
Samsung Internet
完全支持
Webview Andriod
全面支持
相关文章
如何在 JavaScript 中将布尔值转换为字符串?
如何使用 title 标签定义 HTML 文档标题?
在 JavaScript 中,NaN 是如何转换为 Number 的?
HTML 文档的基本标签是什么?
在 JavaScript 中,NaN 如何转换为字符串?
如何在 javascript 中更改属性的值?
有用资源
javascript 参考教程 - 该教程包含有关 javascript 的更多信息:https://www.w3schools.cn/javascript/
打印
❮ 上一节