Coder Social home page Coder Social logo

document.getElementById about writecapture HOT 9 CLOSED

jcugno avatar jcugno commented on August 16, 2024
document.getElementById

from writecapture.

Comments (9)

iamnoah avatar iamnoah commented on August 16, 2024

It's like this script was created just to spite you. The author clearly knows that you can create elements dynamically and append them, which he does for the most part, but instead of a document.body.append, a document.write is thrown in, just to f- with you.

I'll see if there is something writeCapture can do, but this is on the short list of cases that is probably impossible to cover. In this particular case, you could just replace document.write with a noop and put your own div in the document (so it's already there), but that's not exactly future proof.

from writecapture.

iamnoah avatar iamnoah commented on August 16, 2024

So I think we could implement a hack around document.getElementById that returns a temporary element for it to append to, and then move the content to the real element afterwards... but it wouldn't always work. If document.write was used to add content to the real element after the append supposedly happened (which may not be possible, but I'm not sure), then the appended content would end up after that, which would be wrong. e.g.,

document.write('<div id=myDiv>');
document.getElementById('myDiv').appendChild(iframe);
document.write('Something after the iframe</div>');

You would end up with:

<div id="myDiv">Something after the iframe<iframe .../></div>

Or worse, "Something after the iframe" should be outside the div because grabbing it with getElementById closes it.

from writecapture.

iamnoah avatar iamnoah commented on August 16, 2024

I've added a hack that I think might help your case. Try the latest master and add a line somewhere before you use writeCapture that looks like one of these:

 writeCapture.proxyGetElementById = true;
 // or for the jQuery plugin:
 jQuery.writeCapture.proxyGetElementById = true;

from writecapture.

jcugno avatar jcugno commented on August 16, 2024

The scripts keep getting worse and worse, now I see this coming back:

parent_31003.appendChild(iframe_31003);
20var iframeDoc_31003 = document.getElementById("dclkAdsFrameID_31003").contentWindow.document;
21iframeDoc_31003.open();
22iframeDoc_31003.write(adsenseHtml_31003);
23window.setTimeout("iframeDoc_31003.close();", 2000);

.contentWindow is undefined ;)

The people who write the ad scripts are just horrible!

from writecapture.

iamnoah avatar iamnoah commented on August 16, 2024

Eww yea, there really isn't anything we can do about that because it involves native objects. That script will only work on page load, sorry.

from writecapture.

jcugno avatar jcugno commented on August 16, 2024

Ok bleh, thanks for the help though. Appreciate it!

from writecapture.

jcugno avatar jcugno commented on August 16, 2024

What are your thoughts on something like this? I think it's working:

function makeTemp(id) {
var t = global.document.createElement('div');
t.contentWindow = {document : {open : function(){}, html : '', write : function(str){this.html = str;}, close : function(){}}};
state.tempEls.push({id:id,el:t});
return t;
}

and then for the appending:
finish: function() {
each(this.tempEls,function(it) {

                var tempHTML = '';
                if (it.el.contentWindow !== undefined && it.el.contentWindow.document !== undefined && it.el.contentWindow.document.html !== '') {
                    tempHTML = it.el.contentWindow.document.html;
                    var test = document.getElementById(it.id);
                    test.contentWindow.document.open();
                    test.contentWindow.document.write(tempHTML);
                    window.setTimeout(function(){test.contentWindow.document.close();}, 2000);
                }
                var real = document.getElementById(it.id);
                each(it.el.childNodes,function(it) { 
                    real.appendChild(it);
                });
            });
        },

from writecapture.

iamnoah avatar iamnoah commented on August 16, 2024

That's pretty specific... I'm not sure how far mocking it like that will get us, but let me play with this a little bit.

from writecapture.

iamnoah avatar iamnoah commented on August 16, 2024

Support for mocking contentWindow has been added and it seems to work. Check out the latest master.

from writecapture.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.