Is possible to debug dynamic loading JavaScript by some debugger like WebKit, FireBug or IE8 Developer Tool?

前端 未结 12 1251
南方客
南方客 2020-11-27 09:57

From my recent question, I already created some JavaScript function for dynamic loading partial view. So, I can\'t debug any dynamic loading JavaScript. Because all of loade

12条回答
  •  旧时难觅i
    2020-11-27 10:23

    Using Chrome(12.0.742.112) with the code you provided plus a debugger statement like this

        script.text =   "debugger;var someVariable = 0;\n" +
        "someVariable = window.outerWidth;\n" +
        "alert(someVariable);";
    

    chrome_debugger

    works for me.

    I need to modify some JavaScript (limiting scope of all jQuery selector to current partial >view div) before execute it.

    May its more tangible if you bind the selector change to an event on your partial view instead of creating script elements in the html body ( doesnt feel right ).

    You could do something like this

       (function(j)(
          var limiting_selector = '';
          j(".partial_views").bind('focusin over',function(e){
             limiting_selector = j(this).attr('someattr') // or j(this).data('limiting-selector')
          }).bind('focusout out',function(e){
             limiting_selector = '';
          });
          // And then go on with
          // j(limiting_selector+' .someclass')
       ))(jQuery)
    

    This code would always add a limiting selector to all jQuery select operations done while the mouse is in a certain element given the HTML isnt to messed up.

    (Still seems hackerish, may be someone has a better solution)

    cheers

提交回复
热议问题