Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6773985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:43:59+00:00 2026-05-26T15:43:59+00:00

Hello I have code which replaces document.write , makes a buffer and than pushes

  • 0

Hello I have code which replaces document.write, makes a buffer and than pushes buffer into the document:

  var lazyLoad = {

    url: '',
    block: '',
    buffer: '',

    init: function(url,block){
        that = this
        that.url = url;
        that.block = block;

        console.info(this.block)
        console.log(this.url)

        window.d = document
        window.onload = function(){
            that.work()
        }   
    },

    work: function(){
        that = this
        d.write = d.writeln = function(s){ 
                                    that.buffer += s
                                }
        d.open = d.close = function(){}
        s = d.createElement('script');       
        s.setAttribute('type','text/javascript');
        s.setAttribute('src',that.url);
        d.getElementById(that.block).appendChild(s)
        s.onload = function () {
            window.setTimeout(function() {

                console.warn(that.block + ' ' +that.buffer)
                d.getElementById(that.block).innerHTML += that.buffer;
                that.buffer = '';
            }, 0);
       }
    }
}

If I init it once:

lazyLoad.init(
        'http://test.com/test.js',              
         div1
)

But if I call it again with other parameters:

lazyLoad.init(
        'http://test2.com/test.js',             
         div2
)

First init wont work. window.buffer will be empty. Where is my mistake?

P.S. another problem: I tried to replace window.onload with jQuery method $(window).load() but it fires twice. How can I fix it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T15:44:00+00:00Added an answer on May 26, 2026 at 3:44 pm

    basically, you have only one buffer: window.buffer, if you call the init() twice, the window.buffer will be manipulated by the second call, while the first call might not complete. I’d recommend you use a seperate buffer for every init(). which can essentially avoid this issue.

    For your second question,

    window.onload != $(window).load()
    

    window.onload will only execute the method you last assign to it, while $(window).load() maintains a chain, you can init() twice, then there are two methods in the chain.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Problem Hello all! I have this code which takes my jpg image loops through
Hello i have this form filling javascript: function onLine(code,nn) { document.writeform.bericht.value+=code; document.writeform.bericht.focus(); document.writeform.nickname.value+=nn; write1();
Lets say I have this code: <?php class hello { var $greeting = hello;
Hello I have the following bit of code which seems to work, but I'm
Hello I have a php code which by echo calls the javascript function expand(txt)
I have a following code which works fine MsgBox(AddSomething(Of String)(Hello, World)) Public Function AddSomething(Of
I have this code - jQuery('.wymeditor').wymeditor( { html: '<p>Hello, World!<\/p>', postInit: function(wym) { var
Hello all i have the code below which produces four wheels each with the
Hello I have the following code namespace ConsoleApplication2 { class Program { static void
I have following code snippet: class ABC{ public: int a; void print(){cout<<hello<<endl;} }; int

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.