站点的 JavaScript 无法正常工作,它加载到带有自定义 headers 的 Angular iFrame 中
Site's JavaScript is not working which is loaded inside the Angular iFrame with custom headers
在 Angular 8 中需要在 iFrame 中加载站点。
该网站有几个 JavaScript。
要加载该站点,我们必须发送 Authorization
header 请求。
我可以使用以下博客 https://stackblitz.com/edit/angular-iframe-src?file=src%2Fapp%2Fapp.component.html but with this approach, I cannot send authorization headers. So, I tried following Whosebug answer 中提到的方法简单地加载一个 javascript 站点。通过这种方法,我可以成功发送自定义 header 并加载站点,但加载站点的 javascript 无法正常工作,因为我们必须 bypassSecurityTrustResourceUrl
。问题是 bypassSecurityTrustResourceUrl()
(SafeResourceUrl
) 的 return 类型无法传递给 get()
,因为它需要 string
。我该如何克服这个问题?
我可以通过为 <iFrame>
使用 sandbox
元素来解决这个问题,如下所示。
<iframe #iframe width="100%" height="400px" sandbox="allow-forms allow-modals allow-pointer-lock allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-top-navigation"></iframe>
我必须为 iFrame 允许上述权限集。
在 Angular 8 中需要在 iFrame 中加载站点。
该网站有几个 JavaScript。
要加载该站点,我们必须发送 Authorization
header 请求。
我可以使用以下博客 https://stackblitz.com/edit/angular-iframe-src?file=src%2Fapp%2Fapp.component.html but with this approach, I cannot send authorization headers. So, I tried following Whosebug answer bypassSecurityTrustResourceUrl
。问题是 bypassSecurityTrustResourceUrl()
(SafeResourceUrl
) 的 return 类型无法传递给 get()
,因为它需要 string
。我该如何克服这个问题?
我可以通过为 <iFrame>
使用 sandbox
元素来解决这个问题,如下所示。
<iframe #iframe width="100%" height="400px" sandbox="allow-forms allow-modals allow-pointer-lock allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-top-navigation"></iframe>
我必须为 iFrame 允许上述权限集。