Override document.write

65
June 13, 2018, at 2:50 PM

I'm trying to override document.write so i will be able to take the raw html parse it make some manipulations on the code and return the call. My entire process is async so it's needless to say that when document.write is called if the page has finished loading the document.write will erase the entire document, so i can't recall document.write. I've searched and found many discussions about that but almost every one of them is very very old so i can't find any good answer. my code for now is very basic:

 const prevDocWrite = document.write;
 document.write = function(str,patched) {
        if(patched){
            prevDocWrite.call(this, str);
        }else{
            Dom_Parser(str, context).then(newStr => {
                prevDocWrite.call(this, newStr);
            })};
    };

I have added the "patched" part because i'm also calling document.write on my code so i call it like that document.write("str",true) and it will call the original document.write immediately.

I would really appreciate any help or ideas how to make this happen (other projects for reference will be great)

BTW i saw a lot of implementation using innerHtml but that's screwing up the <script> tags:(

Thanks a LOT

READ ALSO
Accessing Object inside Array

Accessing Object inside Array

I'm trying to access values inside Firebase array > object

44
Use anchor element without href to toggle &ldquo;hidden&rdquo; attribute of separate element (div), without JavaScript

Use anchor element without href to toggle “hidden” attribute of separate element (div), without JavaScript

I've been browsing with JS disabled in my browser lately, out of curiosity to see how some sites handle it, and found some functionality on one site in particular that doesn't seem like it would be possible, based on what I know

69
flaticons not showing up in digitalocean - Ruby On Rails application

flaticons not showing up in digitalocean - Ruby On Rails application

I'm using following directory structure as shown in and added the following code in config/applicationrb but flaticons are not showing up in staging server digitalocean while working great on localhost

40
Sass-loader not replacing variables?

Sass-loader not replacing variables?

Not too long ago I made a project that used a combination of SASS variables and CSS custom propertiesI defined my Sass variables and then used those to create my CSS custom properties

94