I need to find all the URLs on the page using jQuery.
They will be static URLS, by that I mean not within anchor tags.
I need to find all the URLs on the page using jQuery.
They will be static URLS, by that I mean not within anchor tags.
How about taking all the content of the document and parse it using a regexp?
To know if a string is a url:
function isUrl(s) {
var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
return regexp.test(s); }
If you want to find all of the literal text URLs - e.g. ones that are not part of an <a>
, this should work:
var regex = /https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?/ig;
var matches = regex.exec($('body').text());