Html javascript打开新窗口并关闭当前窗口 [英] Html javascript to open new window and close current window

查看:2571
本文介绍了Html javascript打开新窗口并关闭当前窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个弹出窗口,在该页面中,我在正文中有以下代码。

I have a popup window and in that page I have the following code in the body.

<a href="http://www.example.com" target="_blank" onClick="javascript:window.close()"><img src="...something"/></a>

目的是在用户点击图片链接时关闭此弹出窗口,并打开一个新页面,并被定向到 http://www.example.com

The purpose is to have this popup window close when a user clicks on the image link, and to open a new page and be directed to http://www.example.com.

它适用于IE和Chrome,但不适用于Firefox。弹出窗口关闭但没有打开新窗口。

It works in IE and Chrome, but not in Firefox. The popup window closes but no new window is opened.

任何想法?

推荐答案

是的,我可以重复这个 - 有趣。 setTimeout 解决它:

Yes, I can repro this - interesting. setTimeout works around it:

onClick="javascript: setTimeout(window.close, 10);"

我只能猜测窗口关闭后(在超链接发生之​​前发生)Firefox停止处理该页。

I can only guess that once the window closes (which happens before the hyperlink is followed) Firefox stops processing that page.

编辑:最好延迟10毫秒 - 1毫秒Chrome不会关闭窗口。

better make it 10ms delay - with 1ms Chrome doesn't close the window.

这篇关于Html javascript打开新窗口并关闭当前窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆