HTML 到 JAVASCRIPT 的转换?

发布于 2025-01-02 05:56:07 字数 342 浏览 1 评论 0原文

<script language="javascript" type="text/javascript">
if (window!= top)
    <a href="#" target="_parent">Go to Top Window</a>;
</script>

我试图让上面的代码工作,但“a href”(HTML)在javascript中不起作用。任何人都可以传播一些关于如何使这个 url 成为 javascript 的一部分的见解吗?由于目标属性和“#”,我确实需要使用 href。这似乎是不可能的..但是如果您对如何解决这个问题有任何想法,请告诉我。

<script language="javascript" type="text/javascript">
if (window!= top)
    <a href="#" target="_parent">Go to Top Window</a>;
</script>

I'm trying to get the above code to work but "a href" (HTML) does not work in javascript. Can anyone spread some insight on how I can make this url be a part of the javascript? And I do need to use href because of that target attribute and the "#". This seems impossible.. but please let me know if you have any ideas on how to approach this.

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

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

发布评论

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

评论(4

为你拒绝所有暧昧 2025-01-09 05:56:07

不是一个明确的问题,但你需要类似的问题,

<script language="javascript" type="text/javascript">
if (window!= top)
    document.write('<a href="#" target="_parent">Go to Top Window</a>');
</script>

Not a clear question but you need something like,

<script language="javascript" type="text/javascript">
if (window!= top)
    document.write('<a href="#" target="_parent">Go to Top Window</a>');
</script>
北恋 2025-01-09 05:56:07

感谢您添加的评论,我认为您正在寻找

<script language="javascript" type="text/javascript">
if (window != top) {
    document.write('<a href="#" target="_top">Go to Top Window</a>');
}
</script>

Thanks to the comment you added, I think you're looking for

<script language="javascript" type="text/javascript">
if (window != top) {
    document.write('<a href="#" target="_top">Go to Top Window</a>');
}
</script>
梦中的蝴蝶 2025-01-09 05:56:07

“谷歌”突破了框架。这是 javascript 的链接: http://www.thesitewizard.com/archive/framebreak.shtml

"Google" break out of frames. here's a link for javascript: http://www.thesitewizard.com/archive/framebreak.shtml

最偏执的依靠 2025-01-09 05:56:07

在您的文档中,为该锚点指定一个唯一的 ID Go to Top Window,然后在 JavaScript 中:

<script language="javascript" type="text/javascript">
    var thatAnchorTag = document.getElementById('hideThisAnchorWhenNotInAFrameset');
    function logicSaysItsAFrameset() {
        return (window != top); //Not really sure if this is the best method.
    }
    if (logicSaysItsAFrameset()) {
        thatAnchorTag.style.display = 'inline';
    } else {
        thatAnchorTag.style.display = 'none';
    }
</script>

In your document, give that anchor a unique id <a id="hideThisAnchorWhenNotInAFrameset" href="#" target="_parent">Go to Top Window</a>, then in your JavaScript:

<script language="javascript" type="text/javascript">
    var thatAnchorTag = document.getElementById('hideThisAnchorWhenNotInAFrameset');
    function logicSaysItsAFrameset() {
        return (window != top); //Not really sure if this is the best method.
    }
    if (logicSaysItsAFrameset()) {
        thatAnchorTag.style.display = 'inline';
    } else {
        thatAnchorTag.style.display = 'none';
    }
</script>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文