badwolfff
asked on
How do I use jQuery to convert a url in these three formats?
The url I need to process is: http://demo.missionfamily.org/index.php?route=product/allevent
and it should become:
mailto: email address has to be empty as it will need to be filled in
subject: whatever I can get from: var thisTitle (whose spaces will need to be converted into %20)
body: whatever I can get from: var thisLink (this will be a url link which will need to be converted to the format compatible with the maito syntax.
So in the third case basically the result should look something like: mailto:?subject=Congrats%2 0Obama&bod y=http%3A% 2F%2Fdemo. missionfam ily.org%2F index.php% 3Froute%3D product%2F allevent&t =All+Event s+Listing
Please help, as I am completely clueless. The rest of the code for the structure where these links have to go I have already managed but I haven't a clue as to how to generate these links
thanks in advance
and it should become:
1.
https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fdemo.missionfamily.org%2Findex.php%3Froute%3Dproduct%2Fallevent&t=All+Events+Listing2.
https://twitter.com/intent/tweet?text=Mission%20Family%20ACLI&url=http%3A%2F%2Fdemo.missionfamily.org%2Findex.php%3Froute%3Dproduct%2Fallevent&via=Mission_Family&original_referer=http%3A%2F%2Fdemo.missionfamily.org%2Findex.php%3Froute%3Dproduct%2Fallevent3.
I don't know how to formulate this one at all, but here are the details:mailto: email address has to be empty as it will need to be filled in
subject: whatever I can get from: var thisTitle (whose spaces will need to be converted into %20)
body: whatever I can get from: var thisLink (this will be a url link which will need to be converted to the format compatible with the maito syntax.
So in the third case basically the result should look something like: mailto:?subject=Congrats%2
Please help, as I am completely clueless. The rest of the code for the structure where these links have to go I have already managed but I haven't a clue as to how to generate these links
thanks in advance
ASKER
Hi Rob,
hmmm... I think you misunderstood me. That I knew how to do. What I need is how to convert the normal URL format in to the appropriate format that facebook/twitter/email take (where spaces become %20, : become %3A, etc.)
thanks
hmmm... I think you misunderstood me. That I knew how to do. What I need is how to convert the normal URL format in to the appropriate format that facebook/twitter/email take (where spaces become %20, : become %3A, etc.)
thanks
ah sorry, then you just use the encodeURI() function:
$(function() {
var url = encodeURI(location.href);
var title = encodeURI(document.title);
var facebook = "https://www.facebook.com/sharer/sharer.php?u=" + url + "t=" + title;
var twitter = "https://twitter.com/intent/tweet?text=Mission%20Family%20ACLI&url="+url+"&via=Mission_Famil y&original _referer=" +url;
var email = "mailto:?subject=Congrats% 20Obama&bo dy="+url+" &t="+title ;
})
$(function() {
var url = encodeURI(location.href);
var title = encodeURI(document.title);
var facebook = "https://www.facebook.com/sharer/sharer.php?u=" + url + "t=" + title;
var twitter = "https://twitter.com/intent/tweet?text=Mission%20Family%20ACLI&url="+url+"&via=Mission_Famil
var email = "mailto:?subject=Congrats%
})
ASKER
Hi Rob,
I am getting the output like this (for another URL):
url = http://demo.missionfamily.org/index.php?route=product/event&product_id=10
title = Test%20event-%20by%20partn er
I think this needs some other type of encoding, don't you? The http:// should become: http%3A%2F%2F
I am getting the output like this (for another URL):
url = http://demo.missionfamily.org/index.php?route=product/event&product_id=10
title = Test%20event-%20by%20partn
I think this needs some other type of encoding, don't you? The http:// should become: http%3A%2F%2F
ASKER
I managed it with encodeURIComponent :D
thanks for pointing me in the right direction.
thanks for pointing me in the right direction.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I've requested that this question be closed as follows:
Accepted answer: 500 points for Rob's comment #a40899696
Assisted answer: 0 points for badwolfff's comment #a40899713
for the following reason:
The solution offered was nearly perfect, just needed a bit of tweaking.
Accepted answer: 500 points for Rob's comment #a40899696
Assisted answer: 0 points for badwolfff's comment #a40899713
for the following reason:
The solution offered was nearly perfect, just needed a bit of tweaking.
LOL you beat me by 30 sec :)
Open in new window