然后使用Javascript进行页面重定向

然后使用Javascript进行页面重定向

本文介绍了如何启动电子邮件客户端,然后使用Javascript进行页面重定向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使网站在其他浏览器上的功能与在IE6中完全相同.当前代码的一部分类似于以下内容:

I'm required to make a website function exactly the same on other browsers as it does in IE6. Part of the current code looks similar to this:

<script>
function myFunc(){
 location.href="mailto:[email protected]&body=Hello!";
 location.href="newPage.html";
}
</script>
<body onload="myFunc();">
</body>

在IE中,这将导致打开邮件客户端并准备好指定的消息,然后将浏览器重定向到newPage.html.但是,其他浏览器仅重定向到newPage.html.如何在浏览器之间一致地实现这种效果(打开邮件客户端,然后执行页面重定向)?
需要说明的是,我也尝试使用元刷新来完成此操作,但未成功.

in IE, this causes the mail client to open with the specified message prepared, and then redirects the browser to newPage.html. Other browsers, however, only redirect to newPage.html. How can I achieve this effect (opening the mail client and then doing a page redirect) consistently across browsers?
As a note, I've also tried to accomplish this using meta refresh, but was unsuccessful.

推荐答案

更改href属性将开始位置加载,然后再次更改该位置将取消以前的导航.

Changing the href property will start a location load, changing it again afterwards will cancel the previous navigation.

似乎IE6将在设置属性后立即启动电子邮件客户端,然后继续执行javascript.其他浏览器的处理方式似乎有所不同,第二个位置加载将取消第一个位置.

It appears that IE6 will start the e-mail client immediately upon setting the property, then continue the javascript execution. Other browsers appear to do things differently, and the second location load will cancel the first.

我设法在Chrome中使用计时器解决了这个问题,它可能也适用于其他浏览器:

I managed to work around this in Chrome with a timer, it might work for other browsers too:

function myFunc(){
  location.href="mailto:[email protected]&body=Hello!";
  window.setTimeout(function () { location.href="newPage.html" }, 0);
}

这篇关于如何启动电子邮件客户端,然后使用Javascript进行页面重定向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 22:53