How to open mailto link in Chrome with Window.open without creating a new tab?

回眸只為那壹抹淺笑 提交于 2019-12-10 18:13:35

问题


I am creating a Google Chrome extension and am trying to open a custom url scheme with (window.open) without having a new blank tab open up. For sake of argument lets try the 'mailto' url scheme.

My code:

window.open("mailto://Bob Lawblah", '_self');

Unfortunately this open up a new blank tab as well as opening up the default mail program even though I specified '_self'. According to this I don't seem to be anything wrong.

Any ideas on how to not have an extra tab open when opening a 'mailto' link?


回答1:


Since this is a chrome extension, there's a different frame of reference for what _self and other targets mean. Instead of trying to use mailto, how about sending them to a site's "Contact Me" page?

I think this offers easier usability for the end user. Honestly, I don't have a default mail application, even if I did have outlook or some dedicated application, I wouldn't use it because GMail is just awesome (personal preference, but I bet I'm not alone). For example, I use an extension to change all mailto links to open GMail so I can email somebody through it. My extensions won't modify your extensions javascript or mailto links (part of the sandboxing).

With a "Contact Me" page, you can not only hide your email address, but allow people to contact you on your terms (no attachments, etc.).




回答2:


Since you're in a Chrome Extension context, you should be using chrome.tabs APIs. If you have an extra tab floating around, you can just close it via http://code.google.com/chrome/extensions/tabs.html#method-remove



来源:https://stackoverflow.com/questions/7098852/how-to-open-mailto-link-in-chrome-with-window-open-without-creating-a-new-tab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!