简体   繁体   English

当用户单击按钮时,React window 没有关闭

[英]React window is not closing when the user clicks the button

I open a React web app like this in my index.js file:我在 index.js 文件中打开一个 React web 应用程序,如下所示:

ReactDOM.render(
    <React.Fragment>
        <Review pplNum={num} />
    </React.Fragment>,
    document.getElementById('root')
)

I then want the user to be able to close it, but close button doesn't work.然后我希望用户能够关闭它,但关闭按钮不起作用。

Here is the Review component:这是评论组件:

import React, { useEffect } from "react";
import axios from 'axios';

const Review = ({ pplNum }) => {
    axios.put('/books/reviews/' + pplNum)
        .then(res => console.log(res.data));
    return (
        <div>
            <div>Thank you for the review</div>
            <div><a href="javascript:window.close">Click here to close</a> this window</div>
        </div>
    );
}

export default Review;

When I click it to close, nothing happens.当我单击它关闭时,什么也没有发生。

Is there something I am not doing correctly?有什么我做的不对吗?

Thanks!谢谢!

You're not calling it as a function:您不会将其称为 function:

<a href="javascript:window.close()">Click here to close</a>

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

相关问题 当用户在React中单击窗口上的后退按钮时,将道具传递给您来自的组件 - Pass props to the component you came from when user clicks back button on window, in React 当用户单击按钮时弹出一个窗口 - pop-up a window when the user clicks a button 当用户点击提交按钮时需要发布并关闭窗口 - Need to POST and close window when user clicks submit button 当用户单击浏览器 React Js 中的后退按钮时关闭模式 - Close a modal when user clicks back button in browser React Js 用户点击按钮后,有没有办法更换 window? - Is there a way to replace the window after user clicks button? 如何在用户单击 Enter Button React js 时停止触发按钮? - How to Stop triggering Button When user clicks Enter Button React js? 用户单击弹出窗口上的保存按钮刷新主窗口 - user clicks on save button on a pop up window refresh main window 创建一个表单提交按钮,当用户单击鼠标右键时启用“在新窗口中打开”吗? - Create a form submit button that enables “open in new window” when the user right clicks? 用户单击外部时隐藏div,除非关闭灯箱 - Hide div when user clicks outside unless closing lightbox 用户在弹出窗口外单击时关闭Bootstrap Popover - Closing Bootstrap Popover When User Clicks Outside Popover
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM