Cannot get URL of a hyperlink column

Mar 3, 2012 at 12:03 AM

I have a simple custom list with a hyperlink column.  Under normal circumstances, I could get the URL as follows:

var url = ($(this).attr("ows_url")).split(",")[0];

However, this will fail if the URL is written like so: http://domain.com/something/0,123,3.html

Notice the comma in the URL? If I split this on the first comma then I will incorrectly receive the following: http://domain.com/something/0

How can I get the URL portion of a hyperlink column when the URL contains a comma?

Mar 3, 2012 at 12:36 AM

Found the answer.  The correct approach is to do the following:

var url = ($(this).attr("ows_url")).split(", ")[0];

It's hard to see but you should split on a comma AND a whitespace.