简体   繁体   English

当我导航到新页面时,Javascript 停止工作

[英]Javascript stops working when I navigate to a new page

I am trying to develop a user interface using html, css, and javascript.我正在尝试使用 html、css 和 javascript 开发用户界面。

I have an "Exit" menu item that uses onclick="window.close();"我有一个使用 onclick="window.close();" 的“退出”菜单项to close the user interface that works when I open any individual page but it stops working as soon as I navigate away from that page, even when I return to the home page.关闭当我打开任何单个页面时有效的用户界面,但一旦我离开该页面,它就会停止工作,即使我返回主页也是如此。

I've never been good at javascript and I have no idea why this is happening and any advice on this would be helpful.我从来都不擅长 javascript,我不知道为什么会发生这种情况,对此的任何建议都会有所帮助。

home.html, about.html, and exit.html (only the active class changes in the list depending on the page) home.html、about.html 和 exit.html(仅活动 ZA2F2ED4F8EBC2CBB4C21A2 列表中的列表会发生变化)

    <!DOCTYPE html>
    <head>
        <title>title</title>
        <link rel="stylesheet" href="css/mystyle.css">
        <script type="text/javascript" src="/eel.js"></script>
    </head>
    <body>
    <ul class="banner">
        <li class="bannerleft"><a class="active" href="home.html">Home</a></li>
        <li class="bannerright"><a href="exit.html" onclick="window.close();">Exit</a></li>
        <li class="bannerright"><a href="about.html">About</a></li>
    </ul>
    <h2>Home</h2>
    </body>
    </html>

Why are you using exit.html as href in a tag you can just put some default page when the user click exit or you can use something like window.history你为什么在标签中使用 exit.html 作为 href 你可以在用户点击退出时放置一些默认页面,或者你可以使用 window.history 之类的东西

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM