简体   繁体   English

如何在点击重定向 url API 时自动关闭新窗口

[英]How To close the new window automatically when the redirect url API is hit

Hello i am using the react js and i am open a new window using this method.您好,我正在使用 react js,我正在使用此方法打开一个新窗口。

var newWindow = window.open(
  this.state.url,
  'myWindow',
  "location=yes,width=600,height=600"
)

Using this method a new window is open and a redirection url is open and getting the response in new window i just want to close new window pop up after getting response.使用这种方法打开一个新窗口并打开一个重定向 url 并在新窗口中获取响应我只想在获得响应后关闭弹出的新窗口。 the redirection link is actually a api link in which i am sending the response.重定向链接实际上是一个 api 链接,我在其中发送响应。

Help me get out of this.帮我摆脱这个。 Thanks谢谢

你可以得到newwindow的事件loadstop然后关闭它。

I think this approach will solve your Issue.我认为这种方法将解决您的问题。 At leas if you open the new Window interaktiv.至少,如果您打开新的 Window interaktiv。 Automatically close browser/tab without opening it by javascript 自动关闭浏览器/选项卡而不用 javascript 打开它

Snippet from the other post which should be part of the response (dont know if possible in your case).来自另一篇文章的片段,它应该是响应的一部分(不知道您的情况是否可能)。

<script language="JavaScript" type="text/javascript">
    function winClose() {
       window.setTimeout("window.close();",2000)
    }
</script>

You have newWindow reference to your window pop up.你有newWindow引用你的窗口弹出。 Now you can listen onload method which gets fired once your window is fully loaded with content and dom is generated.现在,您可以监听onload方法,一旦您的窗口完全加载内容并生成dom ,就会触发该方法。 Refer here. 参考这里。 DO your stuff inside this funciton.在这个函数中做你的事情。

newWindow.onload = function() {
  // do your stuff here
  newWindow.close()
};

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

相关问题 框架关闭并重定向新的url打开同一窗口 - frame close and redirect the new url open same window 在Firefox中打开子窗口时如何自动关闭父窗口 - How to automatically close the parent window when the child window is opened in Firefox Beforeunload无法将用户重定向到另一个页面,如何在尝试关闭窗口/选项卡时将用户重定向到另一个页面/ URL? - Beforeunload is not working to redirect user to another page, how can I redirect user to another page/url when he attempts to close a window/tab? 如何关闭弹出窗口并将URL重定向到父页面? - How to close a pop up window and redirect the url to parent page? 当我单击关闭选项卡或关闭浏览器窗口时,是否可以将页面重定向到另一个URL? - Is is possible to redirect a page to another url when i click on to the close tab or close a browser window? 如何自动关闭模式窗口? - How to close the modal window automatically? 点击广告后如何重定向到新窗口 - how redirect to a new window when a ads are clicked 不使用时如何自动关闭弹出窗口? - How To Close Popup Window Automatically When Its Not In Use? 关闭colorbox并将父窗口重定向到特定URL - close colorbox and redirect parent window to a specific url Javascript:关闭弹出窗口,打开新窗口和重定向 - Javascript: Close Popup, Open New Window & Redirect
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM