建站教程

建站教程

Products

当前位置:首页 > 建站教程 >

如何屏蔽IFRAME里网页的链接跳转

GG网络技术分享 2025-03-18 16:07 3


在做一些网站模板演示网站时,通常需要使用IFRAME调用演示网站。如果演示网站是自己的网站没有问题,如果IFRAME调用的是别人的网站,就会存在这样的问题,如果别人的网站里有其它网站的超链接,用户就会跳转到别人的网站里了。

有没有什么方法可以屏蔽IFRAME里网页的链接跳转呢?其实是可以的,在IFRAME里有以下的属性:

属性描述
align
  • left
  • right
  • top
  • middle
  • bottom
不赞成使用。请使用样式代替。

规定如何根据周围的元素来对齐此框架。

frameborder
  • 1
  • 0
规定是否显示框架周围的边框。
height
  • pixels
  • %
规定 iframe 的高度。
longdescURL规定一个页面,该页面包含了有关 iframe 的较长描述。
marginheightpixels定义 iframe 的顶部和底部的边距。
marginwidthpixels定义 iframe 的左侧和右侧的边距。
nameframe_name规定 iframe 的名称。
sandbox
  • ""
  • allow-forms
  • allow-same-origin
  • allow-scripts
  • allow-top-navigation
启用一系列对 <iframe> 中内容的额外限制。
scrolling
  • yes
  • no
  • auto
规定是否在 iframe 中显示滚动条。
seamlessseamless规定 <iframe> 看上去像是包含文档的一部分。
srcURL规定在 iframe 中显示的文档的 URL。
srcdocHTML_code规定在 <iframe> 中显示的页面的 HTML 内容。
width
  • pixels
  • %
定义 iframe 的宽度。

其中,有一个属性sandbox,就可以限制iframe网页里的链接跳转。它有5个属性值:

描述
""应用以下所有的限制。
allow-same-origin允许 iframe 内容被视为与包含文档有相同的来源。
allow-top-navigation允许 iframe 内容从包含文档导航(加载)内容。
allow-forms允许表单提交。
allow-scripts允许脚本执行。

所以,想要屏蔽IFRAME里网页的链接跳转,就可以使用sandbox属性。代码如下:

<iframe id="J_demoIframe" name="son" src="URL" width="100%" height="100%" scrolling="auto" security="restricted" sandbox="allow-same-origin allow-scripts" frameborder="no" border="0" marginwidth="0" marginheight="0" allowtransparency="yes"></iframe>

这样就可以屏蔽IFRAME里其它网页的链接跳转了。

标签:

提交需求或反馈

Demand feedback