Javascript: Close Popup, Open New Window amp; Redirect(Javascript:关闭弹出窗口、打开新窗口和重定向)
问题描述
我想关闭当前弹出窗口,打开一个新窗口(选项卡)并重定向到特定链接.使用我的 <a>
链接,这非常容易.我只是简单地添加了 "target="_blank"" 并且它工作得很好(它实际上并没有关闭弹出窗口,而是将它最小化,这也很好).
I would like to close the current popup, open a new window (tab) and redirect to a specific link. This works extremly easy with my <a>
links. I simply add "target="_blank"" and it works just fine (it doesnt close the pop up actually, but minimizes it and thats fine too).
由于我正在使用一些具有 onclick 功能的按钮,我想以某种方式在按钮中实现target="_blank"...该按钮现在看起来像这样:
Since I am using some buttons with a onclick function, I want to implent the "target="_blank" in the button somehow... The button looks like this at the moment:
<input type="button" onclick="parent.window.opener.location='http://google.com'; window.close();">
这可行,但问题是它在父窗口中重定向并且没有打开新窗口...
This works, but the problem is that it redirects in the parent window and doesnt open a new window...
Any1 知道如何获得target="_blank" 的功能,以便单击按钮将打开一个新窗口,而不是重定向而不是重定向父窗口?
Any1 has an idea how to get the feature of "target="_blank" so that a click on button will open a new window and than redirect instead of redirecting the parent window?
推荐答案
为什么不在你的 onclick 中使用这个:
Why not just use this in your onclick:
<input type="button" onclick="window.open('http://google.com'); window.close();" />
这篇关于Javascript:关闭弹出窗口、打开新窗口和重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Javascript:关闭弹出窗口、打开新窗口和重定向


基础教程推荐
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01
- 直接将值设置为滑块 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01