嵌入 Liferay 站点,因为 iframe 在外部站点上不工作
Embedding Liferay site as iframe is not working on external site
我有一个包含 Portlet 的 Liferay 页面。我试图将此页面作为 iframe 嵌入到不在 Liferay 中的外部站点中,但它在控制台中给出了以下错误:
Refused to display 'https://example.com' in a frame because it set
'X-Frame-Options' to 'SAMEORIGIN'
我正在使用如下所示的 html iframe 标记来嵌入它:
<iframe allowfullscreen="" frameborder="0" height="400" src="https://example.com" style="border:0" width="500"></iframe>
按照这个主题,我尝试将“&output=embed”放在 URL 的末尾,但它不起作用:Refused to display in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'
我不确定是否需要更改设置或 Liferay 端的任何代码才能使其正常工作。知道是什么原因造成的,我该如何解决?
X-Frame-options
响应header用于防止clickjacking。默认情况下,Liferay 中的所有请求都将此 header 设置为 DENY
以用于所有外部 URL,即 Liferay 站点不能是 iFrame 或嵌入到 Liferay 站点以外的任何其他站点的 iframe 中使用相同的域。
假设您使用的是 Liferay 版本 6.2.x,您可以通过两种方法让 Liferay 成为 iFramed:
Approach-I
禁用 属性 http.header.secure.x.frame.options
到 portal-ext.properties:
http.header.secure.x.frame.options=false
默认为 true
。
Approach-I我(推荐)
将页面的 URL 添加到 portal-ext.properties
中的 属性 http.header.secure.x.frame.options.*
以便只有特定的 URL 可以嵌入 iframe 而不是整个网站。
其中 *
应替换为任何正整数值。
一些示例,请注意每个 URL 都在单独的 属性:
中
http.header.secure.x.frame.options.1=/web/guest/home
http.header.secure.x.frame.options.2=/myPortletPageToBeIframed
http.header.secure.x.frame.options.10=/group/mySite/MyPageInIframe
推荐第二种方法,因为它只允许将特定页面嵌入 iFrame,从而降低其他页面上点击劫持的风险。
我有一个包含 Portlet 的 Liferay 页面。我试图将此页面作为 iframe 嵌入到不在 Liferay 中的外部站点中,但它在控制台中给出了以下错误:
Refused to display 'https://example.com' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'
我正在使用如下所示的 html iframe 标记来嵌入它:
<iframe allowfullscreen="" frameborder="0" height="400" src="https://example.com" style="border:0" width="500"></iframe>
按照这个主题,我尝试将“&output=embed”放在 URL 的末尾,但它不起作用:Refused to display in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'
我不确定是否需要更改设置或 Liferay 端的任何代码才能使其正常工作。知道是什么原因造成的,我该如何解决?
X-Frame-options
响应header用于防止clickjacking。默认情况下,Liferay 中的所有请求都将此 header 设置为 DENY
以用于所有外部 URL,即 Liferay 站点不能是 iFrame 或嵌入到 Liferay 站点以外的任何其他站点的 iframe 中使用相同的域。
假设您使用的是 Liferay 版本 6.2.x,您可以通过两种方法让 Liferay 成为 iFramed:
Approach-I
禁用 属性 http.header.secure.x.frame.options
到 portal-ext.properties:
http.header.secure.x.frame.options=false
默认为 true
。
Approach-I我(推荐)
将页面的 URL 添加到 portal-ext.properties
中的 属性 http.header.secure.x.frame.options.*
以便只有特定的 URL 可以嵌入 iframe 而不是整个网站。
其中 *
应替换为任何正整数值。
一些示例,请注意每个 URL 都在单独的 属性:
中http.header.secure.x.frame.options.1=/web/guest/home
http.header.secure.x.frame.options.2=/myPortletPageToBeIframed
http.header.secure.x.frame.options.10=/group/mySite/MyPageInIframe
推荐第二种方法,因为它只允许将特定页面嵌入 iFrame,从而降低其他页面上点击劫持的风险。