简体   繁体   English

关闭后,Javascript 弹出并没有再次打开焦点

[英]Javascript is popup with focus is not opening again after closing

I am using the onclick function with window.open popup, the popup comes to front with the same button, but after closing it is not opening again我正在使用带有 window.open 弹出窗口的 onclick 函数,弹出窗口使用相同的按钮出现在前面,但关闭后它不会再次打开

<Button hideLabel aria-label={zxxxx "}
    className = {styles.button}
    icon = "plus"
    color = "danger"
    size = "lg"
    circle
    onClick = {
      () => {
        if (!this.state.isOpened) {
          this.setState({
            isOpened: true
          })
          var mywin = window.open("https://app.mural.co", "MsgWindow", "width=1366,height=768")
          mywin.addEventListener("beforeunload", function(e) {
            this.setState({
              isOpened: true
            })
          }, false)
          this.setState({
              windows: mywin
            }

            this.setState(mywin)
          }
          else {
            const window = this.state.windows;
            if (window) {
              window.focus();
            }

          }
        }
      }/>

There is something wrong in your code.你的代码有问题。 Please refer to the commented line.请参阅注释行。


     if (!this.state.isOpened) {
          this.setState({
            isOpened: true
          })
          var mywin = window.open("https://app.mural.co", "MsgWindow", "width=1366,height=768")
          mywin.addEventListener("beforeunload", function(e) {
            this.setState({
              isOpened: true
            })
          }, false)
          this.setState({ // there is no closing parenthesis for this
              windows: mywin
            }

            this.setState(mywin)
          }
          else {
            const window = this.state.windows;
            if (window) {
              window.focus();
            }

          }
        }

Moreover aria-label={zxxxx "} also is missing something. I would highly recommend a code editor that points out these errors for you.此外aria-label={zxxxx "}也缺少一些东西。我强烈推荐一个代码编辑器,为您指出这些错误。

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

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