Initiate Mail From Javascript - javascript

I have a button click event in jquery, Inside which I want to initiate my mailbox on it's click with a particular text as the mail's body that is stored in a variable.
Following is my code:
$('#myButton').click(function(){
$('#btnLaunchEmail').hide();
if (strExternalZippedLink.trim() != '') {
//Here I have to initiate the email
}
})
I tried a lot of things but didn't worked . Can anyone help.

Try Below code:
if (strExternalZippedLink.trim() != '') {
//Lunching the email
var aLink = document.createElement('a');
aLink.href = 'mailto:?body=' + strExternalZippedLink;
aLink.click();
}
strExternalZippedLink will be shown in the body

You need to use a mailto URL. Wiki article: http://en.wikipedia.org/wiki/Mailto
$('#myButton').click(function(){
$('#btnLaunchEmail').hide();
if (strExternalZippedLink.trim() != '') {
var to = "someone#example.com";
var subject = "This is my subject";
var myBody = "This is the message body";
window.location = "mailto:" + to +"?subject=" + subject + "&body=" + myBody;
}
})

Related

How to change page with JS in html?

I want when the user successfully sign up it goes to the main page.
I already tried a lot of function but it doesn't work..
code :
var nama = document.getElementById("name");
var email = document.getElementById("email");
var userPw = document.getElementById("pass");
sign up code :
function store(){
var rePass = document.getElementById("re_pass");
if (userPw.value == rePass.value && nama.value != "") {
alert("Berhasil daftar!");
} else {
alert('Coba periksa lagi~');
return;
}
localStorage.setItem('namaUser', nama.value);
localStorage.setItem('emailUser', email.value);
localStorage.setItem('passwordUser', userPw.value);
i tried this function also :
self.location = 'sign in.html';
}
Try this one. make sure to clear the space between in this segment!!! 'sign in.html'
window.location = 'sign in.html'
Try this.
window.location.replace("/");
or
window.location.href = "/";

Javascript - save clickable link in string

So I have function like this which is called on button click:
function sendEmail() {
var subject = 'test subject';
var href = window.location.origin + window.location.pathname;
var body = 'test body: ' + href;
window.location.href = 'mailto:?subject=' + subject + '&body=' + body;
}
Is it possible to save this href in email body as a real link not as a string ??
Thanks for any suggestions.
No, it's impossible to implement like this because body should be plain text here.
You need to setup your mail function to send Content-Headers for TEXT/HTML instead of TEXT/PLAIN.
If so you can use simple html to send the mail.
That would make the link look like:
function sendEmail() {
var subject = 'test subject';
var href = window.location.origin + window.location.pathname;
var body = 'test body: Any Description';
}
If your solution would work it would be possible to force people to redirect to another page by reading their mails and for sure this should not be the case.

Append image in function jquery

Good evening.
I have this jquery code which allows me, once you press the Enter key, to post a comment.
Fattio that I run an append with the username and the content that the user wants to publish.
In addition to the username I would also like to "hang" the profile picture using their path. How do I post a photo?
Thanks for your help. Here's the code:
function commento_post(id_post)
{
$('.form-commento'+id_post).click(function ()
{
$('#ins_commento'+id_post).keydown(function (e)
{
var message = $("#commento"+id_post).val();
var username = $("#username").val();
var id_user = $("#id_user").val();
if(e.keyCode === 13)
{
$.ajax(
{
type: 'POST',
url: 'http://localhost/laravel/public/index.php/post/ins_commento',
data: { commento: message, id_post: id_post },
success: function(data)
{
$('#commento'+id_post).val('');
$('#commentscontainer'+id_post).append
(
/*$(".username-commento"+id_post).html
(*/
$('<a/>',
{
text : username, href : 'http://localhost/laravel/public/index.php/utente/'+id_user
}).css({'font-weight':'bold'})
//)
).append(' ').append(message).append($('<br/>'));
var el = $('#numero_commenti'+id_post);
var num = parseInt(el.text());
el.text(num + 1);
}
});
}
});
});
}
In your success function, you could simplify everything quite a bit in the following way while not using jQuery append so much, but just using a variable to store your code and then appending it in one go. This will allow you to append all sort of elements, it's easily parseable for the you and it reduces the amount of calls you have to make.
// Add whatever you want your final HTML to look like to this variable
var html = "<a href='http://localhost/laravel/public/index.php/utente/" + id_user + "' style='font-weight: bold;'>" + username + "</a>";
html += message;
// add an image
html += "<img src='path/to/image.jpg' />"
html += "<br />";
// append to code you constructed above in one go
$('#commentscontainer' + id_post).append(html);
Update
I amended an incorrect quote and changed + id_user + "to + id_user + "', which makes everything after it work.

JavaScript/PHP: Get referral key URL

I'm working on an ajax (native JavaScript) form. I'm having trouble getting the referral key and sending it to the PHP back-end.
The idea is that the ajax request sends the entire URL (with the form data) as string to the PHP engine. I can then break down the URL in the PHP and extract the key.
Here is what I have so far:
Page url:
http://example.com?ref=gr84r34ijg98g
JS:
// Send the form data with the URL
function getquerystring() {
var email = document.getElementById('email').value;
var URL = document.URL;
qstr = 'email=' + email + '& URL=' + URL;
return qstr;
}
Then, in my PHP, I can retrieve the form data and url:
$email = $_POST['email'];
$url = $_POST['URL'];
How can I then break-down the URL, so as I only have the code at end as string? I was thinking I could break-down the URL in JavaScript before sending it, although I thought it might be easier to do that part with PHP.
Something like a preg_match() that removes "http://example.com?ref=" would probably do. Although not really sure how to do that.
Yes, you can get the value of ref in Javascript
function getquerystring() {
var email = document.getElementById('email').value;
var URL = document.URL;
var URL_arr = URL.split('ref='); //<-- URL_arr[1] will give ref string
qstr = 'email=' + email + '&URL=' + URL;
return qstr;
}
function getquerystring() {
var email = document.getElementById('email').value;
var URL = document.URL;
qstr = '?email=' + email + '& URL=' + URL;
return qstr;
}
try this.
$email = $_GET['email'];
$url = $_GET['URL'];
There is an extra space before URL .. and you should encode it with encodeURIComponent. Update this line
qstr = 'email=' + encodeURIComponent(email) + '&URL=' + encodeURIComponent(URL);
And on php side
$url = url_decode($_POST['URL']);
$email = url_decode($_POST['email']);
Try this:
var query = window.location.search.substring(1).split('&');
var ref = '';
$.each(query, function(i, v) {
v = v.split('=');
if (v[0] === 'ref') {
ref = v[1];
return false;
}
});
console.log(ref);
Why don't you just do the following in PHP (place it in either a header (if you want it to work on all pages) or at the top of index.php after all your includes :
<?php
$ref = (isset($_GET['ref']) && strlen($_GET['ref']) > 0) ? trim($_GET['ref']) : null;
//Process what ever you wanted to process from the beginning if you had a referral code
if(!is_null($ref)) {
// do your action
}
?>
Using the above you don't really need any kind of javascript.

how to change in below url redirect script

I have a url redirect script that works very well, but i want some change in it.
when i redirect outgoing link then at the end of redirected url i got something like '#lcinside'
example
http://dl.dropbox.com/u/36139836/unknown.html?urlc=http://imgur.com/
goes to
http://imgur.com/#lcinside
but i want to put #lcinside before url start.
example
#lcinsidehttp://imgur.com
i want to put adf url redirect link instead of #lcinside.
how can i put #lcinside before url .
below is script.
please help me.
<script>
function gup(sName)
{
sName = sName.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var sRegEx = "[\\?&]" + sName + "=([^&#]*)";
var regEx = new RegExp(sRegEx);
var aResult = regEx.exec(window.location.href);
if(aResult == null)
{
return "";
}
else
{
return aResult[1];
}
}
if(gup("urlc") != "")
{
window.location = gup("urlc").replace("lcamp", "&") + "#lcinside";
}
</script>
If you are just trying to scrub the referrer, maybe you should use meta refresh
<meta http-equiv="refresh" content="1;url=http://imgur.com/#lcinside">

Categories