开发者

User clicks link in email, it opens email client, how to close window/tab?

开发者 https://www.devze.com 2022-12-28 11:44 出处:网络
A user clicks a lin开发者_运维技巧k in their HTML email, it then goes to a page that simply opens up their email client.

A user clicks a lin开发者_运维技巧k in their HTML email, it then goes to a page that simply opens up their email client.

 window.location.href = 'mailto:...';

I don't want this window/tab to stay open, how can I close it?

window.close() doesn't work since it wasn't opened using window.open()

is it possible?


The browser does not control the mail client, period. It launches an APPLICATION, not a window.


I agree with @Diodeus: using a mailto: link opens an external application which you cannot control via your browser. Even if you could close the window that a web email application loaded, you can't guarantee everyone would launch a webmail app on a mailto: link. Some of us use Exchange/Outlook at work, for example.

If you really want to control the user experience of sending an email from your application, skip mailto: links altogether and offer a page/form that allows the user to enter the email body/subject.

You then process the form and send the email using whatever server-side technology you're using. This can have the benefit of not exposing your email address to spambots.


var new_window = window.open(mailto:foo@bar.com");
new_window.close();

That's what you want.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号