insert a image into outlook - javascript

my site has a "send" button to send email, I want to send some email(outlook) fill with some existed info from my site.
for example, I want a logo image show in the email body,how can I get that?
here is my html and js:
<a id="email" target="_blank" href="">send email</a>
<script>
$('#mail').click(function() {
var link = "mailto: some" + "?cc=cc" + "&subject=subject" + "&body = '"+ ??+"'";
window.location.href = link;
return false;
});
</script>

You cannot do that with a "mailto" url. You will need to either generate the email on your server or use JavaScript in IE on the client side (if your site is in the trusted list) to create a message using the Outlook Object Model. An even then, you would need the image file to be locally present to be able to add to the message.

Related

how to display content instead of download as a file when firing GET Request?

I have a webpage which will display API response in tabular format. I developed this using Angular Js, Sevlets, Java- Rest Assured framework.
Each record in the table has a link to a log file which is an url coming as rest api response.
When I give it as an anchor tag and when I click it from the UI a file is getting downloaded instead of openning in a popup window.
My question here is how can I get the data from url instead of download it as file when user clicks on the link.
<td> <a ng-href="{{item.outputuri}}" target="_blank">Click Log
</a>
</td>
I have read several posts and got to know that we need to set content disposition at server side. But Its not possible so I want to handle it from Client side.
Thanks in advance.
Instead of trying to going to a separate url, how about displaying the content directly on the same page? You can display the content by dynamically creating an IFRAME element and inserting into host directly on your page.
The displayContent method below requests the url and then passes the content to createIframe. That method will create the IFRAME element and write the content to it. I added the base element to the content to make sure any relative links are rendered correctly.
this.displayContent = function(url) {
$http.get(url).then(res => this.createIfram(url, res.data, this.hostElem);
}
this.createIframe = function(baseUrl, content, appendToElem) {
var iframe = document.createElement('iframe');
iframe.className = 'content';
appendToElem.appendChild(iframe);
iframe.contentWindow.document.open();
iframe.contentWindow.document.write('<base href="' + baseUrl + '" />');
iframe.contentWindow.document.write(content);
iframe.contentWindow.document.close();
// do some other processing on the document
}

Is it possible to visit some WWW page with a JavaScript or PHP?

Is to possible to give JS/PHP a link address to some page and make it to visit it or do something with it?
I want to download a content of a page, which address I pass into a form input.
So i would create a form and enter there a page address, like Google.com
<label>Enter address of a page you want me to visit</label><input type="text" id="pageAddress">
And after JS/PHP got there, it would run such function in that sites console:
(function(){
document.location =
'data:text/attachment;base64,' +
utf8_to_b64(document.documentElement.innerHTML); //To Download Entire Html Source
})();
function utf8_to_b64( str ) {
return window.btoa(unescape(encodeURIComponent( str )));
}
So whole script could visit page i want and download it's content. Is it possible?
You can use window.location.assign("url here"); in javascript.

Closing window after running a Google Script web app?

I made a small web app that opens when the user clicks a link in a spreadsheet. The link will take them to web app, which makes changes to a spreadsheet.
I want the browser window to close automatically once the code is finished running.
function doGet(e){
// code make changes to spreadsheet
// here I want browser window to close
return HtmlService.createHtmlOutput(uniqueid + " is marked complete");
};
Thanks for help
A distinction needs to be made between a Web App in a browser tab, and a sidebar or dialog box inside of a Google document (Sheet, Form, Doc).
The question is about a Web App in a browser tab. If you want to close a sidebar or dialog box, then just use:
google.script.host.close()
But this question is for a Web App. You can try putting a script tag in the HTML with code that runs automatically when the window is opened.
<script>
window.top.close();
</script>
If you want a delay:
<script>
setTimeout(function(){ window.top.close(); }, 3000);
</script>
You can try using window.onload.
<script>
window.onload=function(){
console.log("This onload did run");
setTimeout(function(){ window.top.close(); }, 3000);
};
</script>
If you don't care whether the user sees anything or not, you could just run Apps Script Content Service.
I came across your question long after you asked it, but in case you or anyone else is looking for the answer, try this:
To get the browser window to close, create a simple HTML file that instructs itself to close with the instruction window.top.close() like this:
Close Window.html
<!DOCTYPE html>
<html>
<script>
window.top.close();
</script>
</html>
You need to return this as an HTML output so that when the Web App runs, it runs on the client side (as Sandy said in the previous answer). In your scenario, you are already returning an HTML output to inform that some "[uniqueid] is marked complete", and it is assumed that you DON'T wish to close this window after the script runs, else the user will not receive the prompt you intended. That is why you need to keep the instruction window.top.close() outside of the same HTML output that gives this alert. To achieve that, just comma-separate both HTML outputs as two return values.
Here are the two other files that I came up with to model a solution for your use case. FYI: I packaged the user-facing HTML in an email to provide a convenient point of execution, and the code will request an email address for delivery.
Code.gs
function doGet(e){
// code make changes to spreadsheet
var ss = SpreadsheetApp.openById([The key for the spreadsheet you wish you modify])
var sheet = ss.getActiveSheet()
var lastRow = sheet.getLastRow()
var params = JSON.stringify(e);
var paramsArray = JSON.parse(params)
sheet.getRange(lastRow + 1, 1).setValue('Code made changes to spreadsheet at ' + Date())
sheet.getRange(lastRow + 1, 2).setValue(paramsArray.parameter.change)
// here I want browser window to close
var uniqueid = "Someuniqueid"
return HtmlService.createHtmlOutputFromFile('Close Window'), HtmlService.createHtmlOutput(uniqueid + " is marked complete")
};
function mailIt() {
var emailAddress = Browser.inputBox('What email address do you want to send the WebApp to?')
var html = HtmlService.createTemplateFromFile('HTML Email to run Web App')
var htmlCode = html.getRawContent()
Logger.log(htmlCode)
MailApp.sendEmail({
name: "Publish WebApp for survey embed Test",
to: emailAddress,
subject: "Publish WebApp for survey embed Test",
htmlBody: htmlCode
})
}
HTML Email to run Web App
<!DOCTYPE html>
<html>
<form action=[Your current Web App URL in quotes]>
Send text to spreadsheet: <input type="text" name="change"><br>
<input type="submit" value="Submit">
</form>
</html>
Obviously, there are some unanswered questions--like why is it a requirement to automatically close a window while your Web App appears to open only a window that carries a message for the user--but I trust your use case is more complicated than that, and you and others can intelligently leverage the principals in this example to your advantage.
Use the following at the end of the script portion of the HTML file to close a currently open HTML window in Google Sheets:
google.script.host.close();
Instead of using two HtmlServices separated with coma in return statement of your doGet(e) function (that has not worked for me - I got only one return value)
you can put window.top.close(); in onClick event of your submit button like this:
Replace:
<input type="submit" value="Submit">
With:
<input type="submit"
onclick="this.value='Magic ...';
google.script.run.withSuccessHandler(closeWindow); ">
and add somewhere in your html:
<script>
function closeWindow() { window.top.close(); }
</script>
I hope this will be of some use to someone somewhere someday :)
Cheers :)

How to Redirect URL on Google Sites

Okay, so I have a Google Site that I need to redirect to a website.
So for example, I have sites.google.com/xxx/xxx
And when people enter that, I want it to redirect to my website
www.xxxxxxxx.com
How do I do this?
You could bypass this by using js to change href of some hidden element and than use javascript to "click" on this element.
I've used this to create contacts search element directly on sites.
Markup
<button onclick="functionSearch()" id="buttonSearch">
<input type="text" id="inputSearch" value="" placeholder="Search">
Javascript
function functionSearch() {
var inputSearch = document.getElementById("inputSearch");
if (inputSearch.value != "") {
document.getElementById("searchHelper").href = "https://contacts.google.com/search/" + inputSearch.value;
document.getElementById("searchHelper").click();
}
}
On App Script it's not possible.
In App Script , you can do this:
var anchor = app.createAnchor("link", "http://www.google.com");
Look the doc :
=> https://developers.google.com/apps-script/reference/ui/anchor
On javascript :
// click on a link
window.location.href = "http://google.com";
// redirect
window.location.replace("http://google.com");

Automatically open default email client and pre-populate content

I need to automatically open a user's default email client when they save some content on a page. I need to populate the email subject, to address, and put some content in the email body.
What is the best option to achieve this?
I'm aware of the mailto: attribute, but the user must click on this and I'm not sure it allows you to specifiy the subject and content?
As described by RFC 6068, mailto allows you to specify subject and body, as well as cc fields. For example:
mailto:username#example.com?subject=Subject&body=message%20goes%20here
User doesn't need to click a link if you force it to be opened with JavaScript
window.location.href = "mailto:user#example.com?subject=Subject&body=message%20goes%20here";
Be aware that there is no single, standard way in which browsers/email clients handle mailto links (e.g. subject and body fields may be discarded without a warning). Also there is a risk that popup and ad blockers, anti-virus software etc. may silently block forced opening of mailto links.
JQuery:
$(function () {
$('.SendEmail').click(function (event) {
var email = 'sample#gmail.com';
var subject = 'Test';
var emailBody = 'Hi Sample,';
var attach = 'path';
document.location = "mailto:"+email+"?subject="+subject+"&body="+emailBody+
"?attach="+attach;
});
});
HTML:
<button class="SendEmail">Send Email</button>
Implemented this way without using Jquery:
<button class="emailReplyButton" onClick="sendEmail(message)">Reply</button>
sendEmail(message) {
var email = message.emailId;
var subject = message.subject;
var emailBody = 'Hi '+message.from;
document.location = "mailto:"+email+"?subject="+subject+"&body="+emailBody;
}
Try this:
It will open the default mail directly.
<img src="ICON2.png">

Categories