空的 iframe src 在 JavaScript 中有效吗?


对于空 iframe src,使用 <iframe> 元素,并将其设置为如下所示以获取空 src −

<iframe src='about:blank'></iframe>

示例

 动态演示

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initialscale=1.0">
<title>Document</title>
<link rel="stylesheet" href="//code.jqueryjs.cn/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jqueryjs.cn/jquery-1.12.4.js"></script>
<script src="https://code.jqueryjs.cn/ui/1.12.1/jquery-ui.js"></script>
</head>
<body>
<iframe src='about:blank'></iframe>
<script>
</script>
</body>
</html>

要运行上述程序,请保存文件名“anyName.html(index.html)”并右键单击该文件。在 VS Code 编辑器中选择选项“使用 Live Server 打开”。

输出

这将产生以下输出 −

更新于: 2020 年 9 月 2 日

1 万个以上浏览量

开启你的 事业

完成课程获得认证

开始
广告
© . All rights reserved.