Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

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);   } });​ 

live example

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);   } });​ 

live example


Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -