Friday, June 26, 2015

How To Disable Email Engines From Automatically Hyperlinking a URL?

You can turn automatic hyperlinking off easily by following method. There exist other techniques as well to disable email engines from automatically hyperlinking a URL.
There is a zero-width non-breaking space that I like to use: 
I place it in strategic places so that the URL does not get recognized as a URL, like so:
http://wwwdomain.com.
This strategy has worked for me across platforms and rendering clients. Its advantages are twofold:
1) It prevents the client from auto-rendering text as a link, and
2) Unlike other "non-breaking" zero-width space ascii codes (ie ), it wraps the entire URL if your URL happens to need it (instead of just the parts after the zero-width space).
It served my purpose of not allowing email clients to automatically make it a hyperlink.

Ref: http://stackoverflow.com/a/12397389

Thursday, June 4, 2015

How To Get URL And Extract URL Segments Using jQuery?

It is easy to get URL and extract the URL segments dynamically using jQuery.In the below example, I have shown how to get the URL dynamically or setting the URL statically and extract parts or segments of URL.
//Getting the URL dynamically
var url = $(location).attr('href');

//Setting the URL statically
var url = 'http://www.example.com/segment1/example.html';

// Getting the file name i.e last segment of URL (i.e. example.html)
var fn = url.split('/').reverse()[0];

// Getting the extension (i.e. html)
var ext = url.split('/').reverse()[0].split('.').reverse()[0];

// Getting the second last segment of URL (i.e. segment1)
var lm = url.split('/').reverse()[1];
In the above example split the string URL when find "/" (separator) and use reverse save it in an array. Then using the proper index, you can get any part of URL you need (in the above example, we retrieved file name (last segment of URL), extension of file and second last segment of URL).

There are many other ways to get URL and extract URL segments using jQuery. Do share if you have any other good ideas.