Featured post
jQuery: Get value of url in load() function -
i'm using library has defined onclick event handler on hyperlink eg:
<a onclick="$('#mydiv').load('/?__=634285190817664832&sort=id&sortdir=asc&page=1 #mydiv');" href="#">1</a>
how can value of 'url' parameter?
updated answer
...after tobyodavies pointed out (in nicest of ways) being thick. if explicitly retrieve attribute, rather reflected property, we'll string dom, not function, , don't have worry function decompilation (see notes below). remainder of below bit paranoid (because working function decompilation), still:
jquery(function($) { var link, onclick, url, index; link = $('#thelink')[0]; // important: getting *attribute* here, not reflected property. // jquery's `attr` function give property, go direct. onclick = link.getattribute("onclick"); display("onclick = " + onclick); index = onclick.indexof("load('"); if (index < 0) { url = "(unknown)"; } else { url = onclick.substring(index + 6); index = url.indexof("');"); if (index > 0) { url = url.substring(0, index); } } display("url = " + url); function display(msg) { $("<p/>").html(msg).appendto(document.body); } });
original answer
note here there dragons. value of onclick
reflected property time you're accessing in dom function object on browsers, , you'll have use function#tostring
, has never been standardized , mobile browsers known return "[object function]". desktop browsers return decompiled version of event handler, can change @ time.
but you're aware of dragons, can way. here's paranoid approach:
jquery(function($) { var link, onclick, url, index; link = $('#thelink')[0]; onclick = "" + link.onclick; display("onclick = " + onclick); index = onclick.indexof("load('"); if (index < 0) { url = "(unknown)"; } else { url = onclick.substring(index + 6); index = url.indexof("');"); if (index > 0) { url = url.substring(0, index); } } display("url = " + url); function display(msg) { $("<p/>").html(msg).appendto(document.body); } });
- Get link
- X
- Other Apps
Comments
Post a Comment