Running javascript after page is fully rendered

后端 未结 4 646
一向
一向 2020-12-03 10:40

I am trying to create a syntax highlighter script. I tried using my script on a code with 10 thousand lines and all I see is a blank page while it is loading. Everything wil

4条回答
  •  执笔经年
    2020-12-03 11:19

    Not sure exactly how much data is being brought in...but what if on document ready you ran a jquery ajax call and used the completed method to run your highlighter function? If there is a lot of data it will be a slower page load.

    Anyways would like similar to this

    $.ajax({
                type: "POST",
                url: "Where data is actually stored",
                data: { ChannelTypeID: ChannelTypeID },
                datatype: "html",
                beforeSend: function () {
    
                },
                success: function (myHTML) {
                    $('body').html(myHTML);
                },
                error: function () {
                    alert("Ajax request was unsuccessful");
                },
                complete: function () {
                    highlighterFunction();
                }
            });
    

    The complete method specifies a function to be run when an AJAX request completes. Hopefully the success will fire early enough to push the data and allow your highlight to work properly

提交回复
热议问题