javascript - Determine if Link is valid upon user clicking on it -
i offer widget user can store links have created.
so in other words they:
- click add link
- modal pops , enter information: link title, link url, order
- saves db via ajax , refreshes widget display of users links have created.
what when user clicks on link, determine if link exists(could not on domain can see foreseeable issue w/ ajax) if proceed normal open new window , send them on merry way.
however if not generate growl message says like.
i'm sorry link not exist, please verify link.
i need method validating links existence on client side basis. possible ?
you use jquery attach click()
event handler on links, in turn try load url in hidden iframe, if succeeds open link in new window. note expensive way of link checking. maybe smarter done http head request.
edit:
found solution (for plain javascript though) here: http head request in javascript/ajax?
function urlexists(url) { var http = new xmlhttprequest(); http.open('head', url, false); http.send(); return http.status!=404; }
and jquery solution came here: ajax head request via javascript/jquery
ajaxsizerequest = $.ajax({ type: "head", async: true, url: url, success: function(message){ }
as @matt king pointed out these pretty useless cross domain - in case i'd set proxy.aspx page in application query instead. proxy have execute http head request in c#, , return result (success/failure) client/jquery.
Comments
Post a Comment