How to open outlook mail compose window in chrome app? - javascript

I'm working on a chrome application which needs to create an email on click of a button. I'm using mailto: for that and since default client is Outlook, it should open outlook email compose window. I'm using below code for same -
var mail = "mailto:" + recp + "?subject=" + sub;
newWindow = window.open(mail);
When this is executes, chrome app opens outlook email window but also opens a tab in chrome with url as contents of mail variable . and even if I call close on the newly created tab, that does not get closed. My goal is to create email without any additional tab.
Is there any way I could achieve this

You don't have to open new window for this link, since there will be auto-open outlook window (I have no associated action with that type of link, so I get popup to select with that program to open it)
$("span").click(function() {
var recipient = $(this).text();
window.location.href = "mailto:" + recipient + "?subject=Mail to " + recipient;
});
span {
cursor: pointer;
display: inline-block;
margin: 0 10px;
}
span:hover {
border-bottom: 1px dotted black;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<span>sample#mail.com</span>
<span>another#mail.com</span>
<span>sample2#mail.com</span>

Related

gmail compose box not opened with subject and content using JS

The js window.open does not open the IOS compose box, but in android, browser works fine subject and the content is appended.
code:
window.open("https://mail.google.com/mail/?view=cm&fs=1&tf=1&mailto=sri#gmail.com&su=" + 'subject' + "&body=" + 'body' + "&ui=2&tf=1&pli=1", 'sharer', 'toolbar=0,status=0,width=648,height=395');
how to open the Gmail compose box with the subject and content of the mail for all browser compatibility

How to ask permision so others can open mailto

I'm trying to open mail on click in js. I'm using mailto, but in chrome you need to change the handlers settings to make it work.
My question is can I make some sort of popup that ask for persmission and changes this setting to others?
PS: to give permision for me I only found this way:
Open Gmail in Chrome and click the Protocol Handler icon overlapping-diamonds in your browser's address bar.
When prompted to "Allow Gmail to open all email links?", select "Use Gmail," and click "Done."
EDIT
My code to send the mail
$("#applyText").click(function(){
var email = 'mail#gmail.com';
var subject = 'Hire me im a genius';
var emailBody = 'Hi Sample,';
document.location = "mailto:"+email+"?
subject="+subject+"&body="+emailBody;
});
this is browser settings specific, ie. it will behave differently depending on the user's browser settings. The user can change how mailto: links behave in chrome by visiting chrome://settings/handlers, or Chrome Settings->Content Settings->Manage Handlers...
This is an answer to that question.
So to answer your question
No it is not possible because this is browser settings.
But most browsers should open it without a problem. For me this works properly.
By the way, you have some minor mistakes in your code.
Here is an working example
$("#applyText").click(function() {
var email = 'mail#gmail.com';
var subject = 'Hire me im a genius';
var emailBody = 'Hi Sample,';
document.location = "mailto:" + email + "?subject=" + subject + "&body=" + emailBody;
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="applyText">Click</button>

Shopify Public App INSTALL button redirect oddity

This is an oddity that occurs after the Shop's admin user clicks the Install button
The user clicks the 'GET' button and the that works just fine. The next page the user sees is the 'INSTALL' button page.
When the user clicks install a call is made back to my server, I do the request post and get back the applicable token.
Then a get to my server is made and I serve up a page, and that page is rendered in the browser's full window. I would expect it to be in the iFrame of the store's/admin/apps/_myapp_ page.
And if I close the page. Then navigate to store's/admin/apps/_myapp_ the page I host is now properly rendered as you would expect it, in the iFrame.
And tips / thoughts. What is or isn't happening on that click from the 'INSTALL' button
But the way this is the page I sent to the resolution of he 'INSTALL'. I believe I have the re-directs appropriately setup. But maybe you will see something I'm not. This is in Jade/Pug.
extends layout
block content
script(src="/jquery/dist/jquery.js")
script.
function doThePost() {
alert('hello world');
}
h1= title
p Welcome to #{title}
p
p
p
input(type="text", id="shopUrl", name="shopUrl", value="#{shopUrl}", hidden="hidden")
input(type="text", id="shop", name="shop", value="#{shop}", hidden="hidden")
p
button(onclick='doThePost()') v1Demo
p
p end
script(type="text/javascript").
var shpUrl = $('#shopUrl').val();
var shp = $('#shop').val();
// If the current window is the 'parent', change the URL by setting location.href
if (window.top == window.self) {
window.top.location.href = 'https://' + shpUrl + '/admin/oauth?shop=' + shp;
// If the current window is the 'child', change the parent's URL with postMessage
} else {
message = JSON.stringify({
message: "Shopify.API.remoteRedirect"
, data: { location: window.location.origin + '/admin/oauth?shop=' + shp }
});
window.parent.postMessage(message, 'https://' + shpUrl);
}

Internet Explorer Opening Same Page for Different URLs of same website

I have an application where i am doing new tab pop-ups in internet explorer(8,10,11) using window.open(myurl)
The pop-up triggered by a website contains a URL which is another page of that website. Problem here is that when the pop-up takes place, same webpage opens as the one from where the pop-up is being initiated.
If i copy the URL from address bar of the pop-up window and close all windows and than open that URL in new window of internet explorer only than my required page opens in the pop-up window/tab.
(Note: Same application works perfectly fine in Mozila Firefox without any issue, but it is clients requirement to run my application in IE)
Following is a method which is doing the pop-up:
function handlePhonecallScreenpop(callF, callT, callA, custid, entityN) {
var extraqs = "cf=" + callF;
extraqs += "&ct=" + callT;
extraqs += "&cd=outd";
extraqs += "&ca=" + callA;
extraqs += "&cid=" + custid;
extraqs += "&en=" + entityN;
var url = webUrl() + "/main.aspx?etn=phonecall&pagetype=entityrecord&extraqs=" + encodeURIComponent(extraqs);
window.open(url, "callpop");
}
I'm guessing that you aren't setting a target window name. Which means that you're reusing the same target window for EVERY window.open() call. Try adding an arg to each of your calls:
window.open('firsturl', 'windowA');
vs.
window.open('secondurl', 'windowB');
You should see two different windows.
If you change the name to _blank it should always open in a new window.
window.open(url, "_blank");

How to launch a Chrome Extension popup from a background thread?

I want to write a Chrome Extension that will be monitoring for URI link clicks, and when it encounters that it is to launch its popup. I understand that the monitoring will be done in the background thread of the Extension, but I'm not sure how I can launch the popup from the background thread?
Think of the functionality like allowing a simple email editor in a popup - when someone clicks a mailto link, the popup appears to let user write an email and send it without taking them to a new browser window.
I don't think you can do that with registerProtocolHandler, but that doesn't mean you can't write your own content script:
window.addEventListener('click', function (e) {
if (e.target.href && e.target.href.indexOf('mailto:') != -1) {
var email = e.target.href.replace('mailto:', '');
// open your popup when an email is clicked
window.open(...);
}
}, false);

Categories