Jquery not registering the ready func

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • souporpower@gmail.com

    Jquery not registering the ready func

    Hi All
    I am trying to print some HTML using JQUERY. I am posting the code. I
    don't
    see the alert. It seems as though the function is not registered when
    the
    document is loaded. Can someone please clarify what I am doing wrong?
    BTW, I am using IE8 and Chrome to test. Sorry I can't place the code
    in a web site.
    Thanks for your help

    <html>
    <head>
    <script type="text/javascript" src="../../resources/js/
    jquery-1.2.6.js"</script>
    <script language="javas cript" type="text/javascript"$
    (document).read y(function(){ $('.mylink').cl ick(function()
    { $.jPrintArea('# tabularData') }); });

    jQuery.jPrintAr ea=function(el) {

    alert("hello");

    var iframe=document .createElement( 'IFRAME');var doc=null;

    $(iframe).attr( 'style','positi on:absolute;wid th:0px;height:
    0px;left:-500px;top:-500px;');

    document.body.a ppendChild(ifra me);

    doc=iframe.cont entWindow.docum ent;

    var links=window.do cument.getEleme ntsByTagName('l ink');

    for(var i=0;i<links.len gth;i++)

    if(links[i].rel.toLowerCas e()=='styleshee t')doc.write('< link
    type="text/css" rel="stylesheet " href="'+links[i].href+'"></link>');

    doc.write('<div class="'+$(el). attr("class")+' ">'+$(el).html( )+'</
    div>');

    doc.close();

    iframe.contentW indow.focus();

    iframe.contentW indow.print();a lert('Printing. ..');//
    wait(1);documen t.body.removeCh ild(iframe);}

    </script>
    </head>

    <body>
    <div id="tabularData ">
    ....
    </div>
    <a href="#" class="mylink" name="mylink">P rint this Table</a>
    </body>
    </html>



  • David Mark

    #2
    Re: Jquery not registering the ready func

    On Oct 27, 6:14 pm, "souporpo...@gm ail.com" <soup_or_po...@ yahoo.com>
    wrote:
    Hi All
    I am trying to print some HTML using JQUERY. I am posting the code. I
    don't
    see the alert. It seems as though the function is not registered when
    Problem with the ready method in jQuery? Who could have predicted
    that?
    the
    document is loaded. Can someone please clarify what I am doing wrong?
    You are using JQUERY (sic).
    BTW, I am using IE8 and Chrome to test. Sorry I can't place the code
    in a web site.
    Thanks for your help
    >
    <html>
    <head>
    <script type="text/javascript" src="../../resources/js/
    jquery-1.2.6.js"</script>
    ^^^^^^

    There's your mistake. Clear as day.

    <script language="javas cript" type="text/javascript"$
    (document).read y(function(){    $('.mylink').cl ick(function()
    { $.jPrintArea('# tabularData') });      });
    >
    jQuery.jPrintAr ea=function(el) {
    >
    alert("hello");
    >
    var iframe=document .createElement( 'IFRAME');var doc=null;
    Why are you initializing the doc variable to null? You assign a
    document object to it three lines later.
    >
    $(iframe).attr( 'style','positi on:absolute;wid th:0px;height:
    0px;left:-500px;top:-500px;');
    This is what I am talking about. How many function calls is that? I
    will just estimate 1000, several of them will trigger document re-
    flows. All could have been avoided like this:

    var style = iframe.style;
    style.position = 'absolute';
    style.width = style.height = '0px';
    style.left = style.top = '-500px';

    Is that any harder to read than your mess?

    Now your average jQuery "programmer " who is hopelessly conditioned to
    write inefficient code will cry foul at the quadrupling of the lines
    of code. Of course, as minification is the rule these days
    (especially among library users), then the term "lines" is
    meaningless. Count the characters. Then minify and recount. Aha.

    Final tally.

    Function calls: 0
    Re-flows: 0
    Objects created: 0

    Nobody really knows what the tallies are on yours, but God knows they
    aren't good. Lets say 500 function calls + a few re-flows. The
    browser has to get the resources to do this from somewhere, so the
    other programs running on the computer are short-changed. All because
    you didn't want to learn browser scripting.
    >
    document.body.a ppendChild(ifra me);
    Bravo. If you had used a jQuery object to do that, it would have
    added at least a few dozen more function calls (and created and
    discarded another $ object.)
    >
    doc=iframe.cont entWindow.docum ent;
    >
    var links=window.do cument.getEleme ntsByTagName('l ink');
    >
    for(var i=0;i<links.len gth;i++)
    >
    if(links[i].rel.toLowerCas e()=='styleshee t')doc.write('< link
    type="text/css" rel="stylesheet " href="'+links[i].href+'"></link>');
    >
    Strange. It is like you abandoned jQuery half way through.
    doc.write('<div class="'+$(el). attr("class")+' ">'+$(el).html( )+'</
    div>');
    Spoke too soon. This is deranged, even for a jQuery script. That "$"
    does not signify a variable. Stop treating it like one. Better yet,
    stop using it completely.
    >
    doc.close();
    >
    iframe.contentW indow.focus();
    >
    iframe.contentW indow.print();a lert('Printing. ..');//
    wait(1);documen t.body.removeCh ild(iframe);}
    Give it up. The world needs static pages too.

    [snip]

    Comment

    • David Mark

      #3
      Re: Jquery not registering the ready func

      On Oct 27, 6:14 pm, "souporpo...@gm ail.com" <soup_or_po...@ yahoo.com>
      wrote:
      Hi All
      I am trying to print some HTML using JQUERY. I am posting the code. I
      don't
      see the alert. It seems as though the function is not registered when
      the
      document is loaded. Can someone please clarify what I am doing wrong?
      BTW, I am using IE8 and Chrome to test. Sorry I can't place the code
      in a web site.
      Thanks for your help
      >
      <html>
      <head>
      <script type="text/javascript" src="../../resources/js/
      jquery-1.2.6.js"</script>
      <script language="javas cript" type="text/javascript"$
      (document).read y(function(){    $('.mylink').cl ick(function()
      { $.jPrintArea('# tabularData') });      });
      >
      jQuery.jPrintAr ea=function(el) {
      >
      alert("hello");
      >
      var iframe=document .createElement( 'IFRAME');var doc=null;
      >
      $(iframe).attr( 'style','positi on:absolute;wid th:0px;height:
      0px;left:-500px;top:-500px;');
      >
      document.body.a ppendChild(ifra me);
      >
      Sorry "souporpowe r", the re-flows don't apply as you hadn't appended
      the iframe yet. I see this pattern used all the time where it
      triggers dozens of needless re-flows. Yours is not quite that bad.
      Bad enough though.

      Comment

      Working...