href带有“ javaScript”在iframe中没有工作

发布于 2025-02-10 18:38:16 字数 774 浏览 1 评论 0原文

我有page.html以下代码:

<iframe srcdoc="&lt;a href=&quot;javascript:console.log(1)&quot;&gt;test&lt;/a&gt;" sandbox="allow-same-origin || allow-scripts || allow-top-navigation || allow-popups"></iframe>

我允许脚本,最佳动态和弹出窗口。 当我在浏览器中加载Page.html时(Firefox tastest),我可以在iFrame中看到超链接测试,但是这里是问题:当我单击它时 - 在遵循代码时(F12)中没有出现在Console(F12)中:

<iframe srcdoc="&lt;script&gt;console.log(1)&lt;/script&gt;" sandbox="allow-scripts || allow-top-navigation || allow-popups"></iframe>

在控制台中输出“ 1”。 HREF中的JavaScript为什么不工作?

I have page.html where there is following code:

<iframe srcdoc="<a href="javascript:console.log(1)">test</a>" sandbox="allow-same-origin || allow-scripts || allow-top-navigation || allow-popups"></iframe>

I allow scripts, top-navigation and popups.
When I load page.html in browser(Firefox Lastest), I can see hyper-link test in iframe, but here is the problem: when I click it - nothing appears in console(F12) while following code:

<iframe srcdoc="<script>console.log(1)</script>" sandbox="allow-scripts || allow-top-navigation || allow-popups"></iframe>

Outputs "1" in console.
Why wouldn't the javascript in a href work?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

过度放纵 2025-02-17 18:38:16
  • 您错过了HREF中的一些代码(javaScript:...
  • 允许same-origin:如果不使用此令牌,则将资源视为来自特殊总是失败的相同原始政策的来源。请参阅 mdn doc
  • You missed some code in your href (javascript:...)
  • allow-same-origin: If this token is not used, the resource is treated as being from a special origin that always fails the same-origin policy. see MDN doc here
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文