How recognize the URL enter by user in comment box? - javascript

I am working on one social network application. In this application user can put comment like they did in Facebook.
If user enter any external link as comment, i want to highlight that link and if somebody click on it so it need to get open in other tab.
If user enter any link or URL in comment box i want handle it like Facebook did
How i can achieve this

Here's the link to find proper URL:
What is the best regular expression to check if a string is a valid URL?
Also once you get to know it's a proper url, wrap it in an anchor tag and add target=blank property to it.

Related

Is there a way to capture the body of an email message automatically and insert into a hyperlink (as a variable) and send to Google Translate?

In an effort to support our schools' English Language Learners (ELLs) and their non-English Speaking parents, I was wondering if it is possible to automatically capture the body of an email (we use GMAIL) and insert it into a hyperlink in the signature as a variable.
The end goal would be for the parents to receive the email, click on the link to translate it, and have the source box of Google Translate already populated with the email body. All the parent would need to do is select their target language.
So, for example, in GMAIL, if I have a message:
Hi Trish,
What do you think?
Allan
With a signature of:
Click here to read this message in your preferred language
Click <a href a="https://translate.google.com/?sl=auto&tl=es&op=translate">here<a> to read this message in your preferred language.
What I would like to have happen is for the hyperlink to automatically grab the text from the email and build the signature hyperlink like this:
Click <a href a="https://translate.google.com/?sl=auto&tl=es&text=Hi%20Trish%2C%0A%0AWhat%20do%20you%20think%3F%0A%0A-Allan%0A&op=translate">here<a> to read this message in your preferred language.
Is this possible? Any help or ideas would be greatly appreciated.
Thanks,
Allan

How Can I Integrate Facebook With My Own Like Button

I have a like button on my own website, and I want it to function just like it currently does, with the additional feature that it also makes a post on the person's facebook timeline "John Smith liked this post on www.example.com" where www.example.com is my website. How can this be achieved?
Facebook has documentation for how to put their own like button but I don't want theirs, I just want what I already have to have that one functionality.
First of all, you are not allowed to use custom graphics for the Like Button, you MUST use their own one.
You can use og.likes to create your own Like Button: https://developers.facebook.com/docs/reference/opengraph/action-type/og.likes
A message about the User having liked something shows up automatically on Facebook, you can't "autopost" it additionally. It would require to authorize a User with the publish_actions permission, and it will definitely not get approved by Facebook because the message parameter must be 100% User generated:
Don't prefill captions, comments, messages, or the user message parameter of posts with content a person didn’t create, even if the person can edit or remove the content before sharing.
Source: https://developers.facebook.com/policy/
If you know how to put their button on your page, you should also know how to put your own button on your page. It should be as easy as changing code between
<a href...>
and
</a>
I just googled 2 min and came up with this:
https://developers.facebook.com/docs/plugins/like-button
It says: Use this URL in an iframe or as a link to your plugin.
http://www.facebook.com/plugins/like.php?href=https%3A%2F%2Fyoururl.com&width&layout=standard&action=like&show_faces=true&share=true&height=80
Just change yoururl.com to whatever it should like.

Can I verify the content of a Twitter Tweet through a callback?

I'm trying to integrate twitter into my site in a way that allows me to give a member of my site 'points' for tweeting about the site. Everything is working so far, except I can't figure out how to ensure that the user is actually saying something related to my site.
Basically, once the user submits a tweet, I would like to verify that the tweet contains my hashtag. The rest of the text can be whatever they like, but I don't want to give them points if they delete the hashtag from the tweet.
I'm using the javascript tweet button, and I put my code for assigning points inside of
twttr.events.bind('tweet', function(event) { ... });
How can I check what the user tweeted?
Thanks!

Facebook Sharer not giving Title

I have added a facebook button to my company's site so that people can quickly distribute surveys to users via facebook. It is a pretty simple JavaScript:
function SFace()
{
window.open("http://www.facebook.com/sharer/sharer.php?u=[[:SurveyUrl:]]","Facebook","width=700,height=300,toolbar=0,resizable=0");
}
<img src="http://www.snap-surveys.com/test/face.jpg" onClick="SFace()" />
It works fine, but people want a customized title to appear. So, I added &t=Something, however, when you click the link, it still just shows the long URL. I thought maybe it was because I wasn't using encodeURIComponent. So, I added a variable
var SFace="http://www.facebook.com/sharer/sharer.php?u=[[:SurveyUrl:]]&t=something"; document.write(encodeURIComponent(uri));
And then using that in the function. Same thing, shows the URL and not the title. What exactly am I doing wrong? How can I get it to show a custom title in the shared link?
In case anyone wanted to know my solution:
First needed to get an App ID from Facebook (get the developer's app, create a new app and set the URL as the base/common domain for the site with the button you are adding). Once you have the ID The URL is:
http://www.facebook.com/dialog/feedredirect_uri=THE_URL&app_id=YOUR_APP_ID&link=THE_URL_YOURE_LINKINGTO&name=TITLE_YOU_WANT_TO_DISPLAY
My recommendation is to write the full URL out like normal and create a variable with document.write(encodeURIComponent); like in my example above. This will add the appropriate spacing characters.
If the URL matches the URL listed in the App, you can have a share link with a custom title and can therefore use your own button and not the default Like button that facebook provides.

Facebook-like textbox that fetches a URL's contents upon paste

hi all i stuck at a point in which i want to ma a multiple line text box to work just like a FACEBOOK text box . i.e. when a URL is pasted or typed (along with the text) it will it fetches the information from the page specifed by URL
well i found somthing at
This post
i want to know how to get URL in VAR in javascript
coz when i enter a url it fetches complete information how ever when i put another url it treat it as a text
Constantly search the text for a url via regex, possibly on a javascript event like onkeyup. Use ajax to load the page, and scrape out whatever info you want to display.
http://www.devguru.com/technologies/ecmascript/quickref/evhan_onkeyup.html
http://regexlib.com/Search.aspx?k=URL

Categories