why Whatsapp web api not sending &? - javascript

I'm using this Javascript to send some information to someone on whatsapp but don't know why Javascript is not sending my message after using & I write it after company name. it is very necessary to use this in middle of the text. what should I do?
I want to use & after conpnayName so I can deliver what I want to the my client.
function whatsapp(){
var compnayName = $("input[name=companyName]").val();
var p_number = $("input[name=p_number]").val();
console.log(s_no)
window.open( "https://api.whatsapp.com/send?phone=+91"+ p_number +"&text=" +"Download Your Bill from : http://localhost/learn/php_invoice/search-bill.php?order_id="+ compnayName + "&" + "p_number" + p_number ,'_blank');
}

You should url encode the "&" for that specific symbol.
Take a look at url encoding https://www.w3schools.com/tags/ref_urlencode.asp
Try something like,
window.open( "https://api.whatsapp.com/send?phone=+91"+ p_number +"&text=" +"Download Your Bill from : http://localhost/learn/php_invoice/search-bill.php?order_id="+ compnayName + "%26" + "p_number" + p_number ,'_blank');
Here "%26" refers to "&".

Related

Setting a href inside of template literals

I'm trying to make use of a nice email template for when a user signs up with their email, I'm using express & node mailer to accomplish this. Previously my code looked like:
"Hello, " +
user.username +
",\n\n" +
"Please complete your registration by clicking the link:
\nhttp://" + req.headers.host + "/confirmation/" + user.username + "/" + token.token +
"\n\nThank you!\n"
Inside of my HTML template, which is a template literal ive tried this:
const output = ` <a href="${req.headers.host} + "/confirmation/" + ${user.username} + "/" + ${token.token}" `
but this doesn't work, theres no href on the <a> inside of the email.
I must be missing something really basic... thanks for looking =)
With `` you don't need to concatenate the string with +, so it should look like this:
const output = ``

Foreign letters failing when sending emails

I sometimes have to send emails in a German and I need to use ö ä ß etc... I have text written containing these letter and using alert() they appear just fine. I have code to send an email :
var link = "mailto:" + SendTo
+ "&cc= "
+ "&subject=" + escape(subjectLine)
+ "&body=" + escape(BodyText);
window.location.href = link;
When I click a button to send the email, the text is missing these foreign letters e.g gruß comes out as gru. Do I need to put anything in here to make sure these letter don't disappear?
Thank you in advance
The following articles shows how to decode the letters using javascript :
Javascript decoding html entities
function decodeHtml(html) {
var txt = document.createElement("textarea");
txt.innerHTML = html;
return txt.value;
}
HTML Entity Decode
Using jquery:
varTitle = $('<textarea />').html("Chris&apos; corner").text();

Json Individual Links in Table column

I have one page with a json table pulling in information from the json api. This works fine. Now my issue is, On the far right column i'm wanting a link to another page of mine, This link will be a unique link. At the moment, As you can see by the code, i can get it to link to the html page 12345, But all the rows link through to this. Which does not help Ha!
I'm ideally wanting the first button to link to 1.html then second button to link to 2.html and so on and so forth.
Here is the code i have so far.
for(var i =0;i < json.results.collection1.length;i++) {
var title = json.results.collection1[i].Name.text;
var venue = json.results.collection1[i].Venue.text;
var date = json.results.collection2[i].Date;
var button = "<button class='redirect-button' data-url='12345.html'>Link</button>";
$("#apple").append("<tbody><tr><td>"+title+"</td><td>"+venue+"</td><td>"+date+"</td><td>"+button+"</td></tr></tbody>");
$("#apple").find(".redirect-button").click(function(){
location.href = $(this).attr("data-url");
});
}
},
Obviously all help would be greatly appreciated. Thanks Sam
Just to explain the comment above
The link you're creating is a <button> but really it's just a string.
So by concatenating the URL part of the string based on something (like your i index in your loop) you can change it to anything you want.
so for example :
var button = "<button class='redirect-button' data-url='" + i + " .html'>Link</button>";
this gives an element that looks like :
<button class='redirect-button' data-url='0.html'>Link</button>
would give you 0.html, 1.html, etc (change the data-url='" + i + " .html' to data-url='" + (i+1) + " .html' and you get 1.html, 2.html, 3.html...)
or if you can change the API to give you a proper link in the return you can make it a bit more readable with:
var button = "<button class='redirect-button' data-url='" + json.results.collection2[i].LinkUrl + " .html'>Link</button>";
results in :
<button class='redirect-button' data-url='abcd.html'>Link</button>
assuming the return is called LinkURL and it's value is 'abcd'
Finally you append this string to the $("#apple") element and then the click event is added that looks for the data-url value and changes the current browser location to that new value.

HTML and JavaScript make search input ready for URL

I am making a webpage so I can search google from a custom page.
But when I click search it does search my input on google but the URL should be different when I input # and % and all these characters.
So my question is how do I convert something like this :
http://www.google.com/#q=Hello World C#
to this :
http://www.google.com/#q=HEllo+world+C%23
using JavaScript
EDIT :
This is the function I tried to use
$('button#SubmitSearch').click
(
function()
{
window.location = encodeURIComponent("https://www.google.nl/#q=" + $('input#SearchBar').val());
}
);
and
$('button#SubmitSearch').click
(
function()
{
window.location = "https://www.google.nl/#q=" + $('input#SearchBar').val();
}
);
Using encodeURI, eg :
console.log(encodeURI('http://www.google.com/#q=Hello World C#'));
> "http://www.google.com/#q=Hello%20World%20C#"
Or
encodeURIComponent
console.log(encodeURIComponent('Hello World C#'));
> "Hello%20World%20C%23"
From your OP :
$('button#SubmitSearch').click(function(){
window.location = "https://www.google.nl/#q=" + encodeURIComponent($('input#SearchBar').val());
});
use the function encodeURIComponent:
encodeURIComponent('this is a string with special characters like # and ?')
hope it helps :)
try this
Var search = document.getElementById("searchbox");
Then use addeventlistener or onClick
key=key.replace(/ /g,"+");
document.location("http://google.com/#q" + search.value);

How to include javascript generated text into html link?

I have a javascript that displays a generated text into a div:
document.getElementById('phrase').innerHTML = phrase;
PHRASE_TEXT_GETS_SHOWN_HERE
Basically I'm trying to set up a link that will take the text and post it to twitter with a link:
Clicky for tweety
How can I include the generated text in the link?
Do you mean like:
function setPhrase(phrase) {
var url = 'http://twitter.com/home?status=' + encode(phrase);
$('#phrase').html('' + phrase + '');
}
...?
Un-jQuerying it should be straightforward enough, if that's how you roll.
This is un-jQueried:
function setPhrase(phrase) {
var url = 'http://twitter.com/home?status=' + encodeURI(phrase);
document.getElementById('phrase').innerHTML = '' + phrase + '';
}
If you didn't see my failbraining encode for encodeURI as an error you should use Firebug. It may also fail if you have more than one element with the id phrase or if you have no elements with the id phrase.

Categories

Resources