Comments (9)
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.
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.
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.
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.
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.
Ok bleh, thanks for the help though. Appreciate it!
from writecapture.
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.
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.
Support for mocking contentWindow has been added and it seems to work. Check out the latest master.
from writecapture.
Related Issues (20)
- Problem with writeCapture + Pointroll ads HOT 16
- TypeError in replaceWith (nolib-support.js) HOT 2
- Ads not respecting destination div#id and loading in the wrong place HOT 3
- Incompatible with AdSense/DFP? HOT 2
- Using writeCapture to change ads through a gallery HOT 1
- How Do I Install This Plugin? HOT 3
- Ad fails in IE with writeCapture HOT 7
- Fails with <script foo="bar"src="baz"> HOT 1
- Two ads on a page causing type error HOT 2
- el is undefined when calling the function before currents adds have finished HOT 1
- Wait to finish before next capture? HOT 3
- Ajax callbacks not firing properly HOT 8
- doXDomainLoad fails to make a network request HOT 1
- In safari 5.1 writeCapture dosent work properly HOT 3
- Problem in safari browsers & problem in working with writeCapture 2 HOT 1
- Ad load for specific ad format blocks other successive ads on page. HOT 1
- Error: no element in writen markup with id __ executing code: <proxyGetElementById - finish> HOT 1
- Ads code loading into wrong destination HOT 1
- Does not emulate document.write properly with Rich Ads HOT 2
- [enhancement] Add missing bower.json.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from writecapture.