I'm trying to send a recorded message by mail, but no mail client or message is opening when send button is clicked even if the function is running,
function sendMail(media) {
$('#send').click(function() {
var link = "mailto:me#example.com"
+ "?cc=myCCaddress#example.com"
+ "&subject=" + escape("This is my subject")
+ "&body=" + media
;
window.location.href = link;
});
}
whats the problem in my script?
In your sendMail function you create a handler for your button. So you need to call sendMail(); once after declaration to create a handler. I think there is no point in creating separate function if you're going to use it just once. You should do this:
$(function() {
$('#send').click(function() {
var link = "mailto:me#example.com"
+ "?cc=myCCaddress#example.com"
+ "&subject=" + escape("This is my subject")
+ "&body=" + media;
window.location.href = link;
});
});
Related
The telegram bot must send a message to the user with force_reply active.
Inserting the link in the address bar works; the bot sends the message and the answer function is already active. The same link, generated by the code in Google Apps Script, does not work; the bot does not send anything.
Working link: (I replaced the id of my bot and the ID of the chat with BOT_TOKEN and CHAT_ID)
https://api.telegram.org/BOT_TOKEN/sendMessage?chat_id=CHAT_ID&text=force_replyTest&reply_markup={"force_reply":true}
code to generate the link
var url = "https://api.telegram.org/bot" + token;
function sendText(idChat,text) {
var response = UrlFetchApp.fetch(url + "/sendMessage?chat_id=" + idChat + "&text=" + encodeURIComponent(text) + '&reply_markup={"force_reply":true}');
Logger.log(response.getContentText());
}
if(text == "/p"){
sendText(idChat,"force_reply test");
}
Thank to #TheMaster
Work with this code
var response = UrlFetchApp.fetch(url + "/sendMessage?chat_id=" + idChat + "&text=" + encodeURIComponent(text) + '&reply_markup=' + encodeURIComponent('{"force_reply":true}'));
Heyho, I want to add GET params like?USER_NAME=Max&USER_ID=01 to the URL if the page gets reloaded. I already got a few snippets for changing the URL / adding params. But I need something to detect the page reload and execute a function. Or a way to change the path of the Url directly if the page gets reloaded.
I tried several things like beforeunload and navigation types.
$(window).bind('beforeunload', function() {
// EDIT: vars like uname etc are defined
var newurlgetstring = "?USER_NAME=" + uname + "&USER_EMAIL=" + uemail + "&LAST_NAME=" + lname + "&PRE_NAME=" + fname + "&UTITEL=" + utitel + "&U_ID_T=" + uidt + "&MV=" + mv + "&V=" + uv ;
var newurl = window.location.protocol + "//" + window.location.host +window.location.pathname + newurlgetstring;
window.history.pushState({path:newurl},'',newurl);
});
But I want able to execute a function with beforeunload. I was just able to display a return question.
i am developing an application and loading an hosted application using the inapp browser plugin cordova-plugin-inappbrowser
I have gotten most of the functionalities to work but i am unable to get the part of loading an error message when he url does not load, it dosent just work and shows me an error message of the url where i have hosted my application instead.
Which could be embarrassing.
please i need help on this
This is what am working with below thanks for ur potential responses
// my child browser code, the main source of my app content
function fire(){
var ref = cordova.InAppBrowser.open('http://####################', '_blank', 'location=no,zoom=no,hardwareback=yes,clearsessioncache=yes,clearcache=no');
var myCallback = function(event) { alert(event.url); }
ref.addEventListener('loadstart', inAppBrowserbLoadStart);
ref.addEventListener('loadstop', inAppBrowserbLoadStop);
ref.addEventListener('loaderror', loadErrorCallBack);
ref.addEventListener('exit', inAppBrowserbClose);
}
function loadErrorCallBack(params) {
$('#status-message').text("");
var scriptErrorMesssage =
"alert('Sorry we cannot open that page. Message from the server is : "
+ params.message + "');"
inAppBrowserRef.executeScript({ code: scriptErrorMesssage }, executeScriptCallBack);
inAppBrowserRef.close();
inAppBrowserRef = undefined;
}
function executeScriptCallBack(params) {
if (params[0] == null) {
$('#status-message').text(
"Sorry we couldn't open that page. Message from the server is : '"
+ params.message + "'");
}
}
Your code is generally fine, but you have no control over the title of the alert() function. You can use some other techniques to display the error message. For example, you can use a div:
function loadErrorCallBack(params) {
$('#status-message').text("");
var scriptErrorMesssage = createMsg('Sorry we cannot open that page. Message from the server is: '
+ params.message);
inAppBrowserRef.executeScript({
code: scriptErrorMesssage
}, executeScriptCallBack);
inAppBrowserRef.close();
inAppBrowserRef = undefined;
}
function createMsg(msg) {
return 'var div = document.createElement("div");'
+ 'div.style.position = "absolute";'
+ 'div.style.top = "50%";'
+ 'div.style.left = "50%";'
+ 'div.style.width = "100px";'
+ 'div.style.height = "100px";'
+ 'div.style.color = "#f00";'
+ 'div.innerHTML = "' + msg + '";'
+ 'document.appendChild(div);'
}
I tried this with umpteen examples we see on the net. But I guess there is none that is simple and works on all browsers (IE 8 and above as well).
I am trying to simply open up Outlook window with mailto link.
Email
JQuery:
$(function () {
$('#emailLink').on('click', function (event) {
alert("Huh");
var email = 'test#theearth.com';
var subject = 'Circle Around';
var emailBody = 'Some blah';
window.location = 'mailto:' + email + '?subject=' + subject + '&body=' + emailBody;
});
});
Granted, I am a jQuery newbie. The above just doesn't work. It just flickers the browser but nothing opens. I guess this is because of window.location.
Is there a simple solution? I want this to work in IE8 & above and in all browsers.
The body is generated automatically (in JSP).
here's working solution:
Email
and the function:
$(function () {
$('#emailLink').on('click', function (event) {
event.preventDefault();
alert("Huh");
var email = 'test#theearth.com';
var subject = 'Circle Around';
var emailBody = 'Some blah';
window.location = 'mailto:' + email + '?subject=' + subject + '&body=' + emailBody;
});
});
If you do not need the address as a text anywhere on the website I would suggest this:
$('a[data-mail]').on('click', function() {
window.location = 'mailto:' + $(this).data('mail')+'#yourdomain.net' + '?subject=Spotflow';
});
The link woud look like this:
Send me a mail
No chance for bots!
$(function () {
$('[name=emailLink]').click(function () {
var email = 'test#theearth.com';
var subject = 'Circle Around';
var emailBody = 'Some blah';
$(this).attr('href', 'mailto:' + email +
'?subject=' + subject + '&body=' + emailBody);
});
});
.click can be replaced with .mousedown and so on.. or just
$(function () {
$('[name=emailLink]').each(function() {
var email = 'test#theearth.com';
var subject = 'Circle Around';
var emailBody = 'Some blah';
$(this).attr('href', 'mailto:' + email +
'?subject=' + subject + '&body=' + emailBody);
});
});
Your selector is looking for an ID
$('#emailLink')
But you have only specified the name.
Add id="emaillink" to the anchor tag.
You don't need any javascript/jQuery at all for this, just the following HTML should do:
Email
Can't seem to get this javascript redirect to work?
Suggestions?
Should I maybe do it with a meta refresh and how?
// If we have a successful location update
function onGeoSuccess(event)
{
document.getElementById("Latitude").value = event.coords.latitude;
document.getElementById("Longitude").value = event.coords.longitude;
document.getElementById("location").href = "track.cfm?track=s&Lat=" + event.coords.latitude + "&Long=" + event.coords.longitude;
var redirectUrl = "track.cfm?track=s&Lat=" + event.coords.latitude + "&Long=" + event.coords.longitude;
}
// If something has gone wrong with the geolocation request
function onGeoError(event)
{
alert("Error code " + event.code + ". " + event.message);
}
function redirect()
{
window.location = redirectUrl;
}
setTimeout(redirect,15000);
The problem is the scope of redirectUrl variable. You declared redirectUrl as local for onGeoSuccess function, so it will be visible only inside of it. For workaround ,you can put all this stuff:
function redirect()
{
window.location = redirectUrl;
}
setTimeout(redirect,15000);
inside of onGeoSuccess function, or make redirectUrl global, by removing var before redirectUrl:
redirectUrl = "track.cfm?track=s&Lat="+...
//^-----no 'var'
Declare redirectUrl in parent scope, and run onGeoSuccess function.
var redirectUrl;
function onGeoSuccess (event) {
document.getElementById("Latitude").value = event.coords.latitude;
document.getElementById("Longitude").value = event.coords.longitude;
document.getElementById("location").href = "track.cfm?track=s&Lat=" + event.coords.latitude + "&Long=" + event.coords.longitude;
redirectUrl = "track.cfm?track=s&Lat=" + event.coords.latitude + "&Long=" + event.coords.longitude;
}
function onGeoError (event) {
alert("Error code " + event.code + ". " + event.message);
}
function redirect () {
window.location = redirectUrl;
}
onGeoSuccess(...);
setTimeout(redirect, 15000);
Two problems:
1) The redirect URL is being set by a function which, at least from the code you posted, is not being called
2) Even if it was called, redirectUrl is a local variable to that function, so the timeout cannot access it.
Always check the error console.