Coder Social home page Coder Social logo

iamnoah / writecapture Goto Github PK

View Code? Open in Web Editor NEW
241.0 20.0 38.0 1.71 MB

Utility to assist the Ajax loading of HTML containing script tags that use document.write. Mailing List: http://groups.google.com/group/writecapturejs-users

Home Page: http://iamnoah.github.com/writeCapture

License: Other

Groovy 3.32% JavaScript 96.68%

writecapture's Introduction

NEWER! Checkout PostScribe! It's awesome.

NEW! Checkout this branch for a completely rewritten writeCapture that should be much more compatible with a greater variety of scripts.

Usage Summary

$(something).writeCapture().html('some html with document.write scripts');

or if you just want to force your ads to load async:

$.writeCapture.autoAsync();

writeCapture can be used with or without jQuery and can be loaded asynchronously. For async loading, [[ControlJS]] is a good option, but any async loading library or technique should work. See the wiki for more detailed usage.

Need help? See "Help!" below.

Dependencies

writeCapture.js was developed using jQuery 1.3.2, but should work with most versions. We recommend you use jQuery, because it's pretty great, however, if that's not possible, there is support/nolib-support.js, which provides a bare bones implementation of the support functions jQuery would otherwise provide and only adds about 800 bytes when Gzipped.

To use nolib-support, just grab the latest writeCapture-x.x.x.-nolib.min.js from the downloads section. It already includes writeCapture.js, so it's the only file you need. If you'd like the unminified source for debugging, simply include nolib-support.js before writeCapture.js.

Note that nolib does not implement onLoad, which is required for autoAsync.

If you already have another Ajax library you are using like Prototype or dojo, you can implement write capture support yourself.

Why should I care about writeCapture.js?

Sometimes we are forced to use a third party script or markup that we simply cannot change (usually an Ad server). While our websites are sleek and snappy with a nearly pristine codebase and progressive enhancement and Ajax everywhere, many 3rd party libraries are still using tables for layout and the dreaded, evil document.write method.

What makes document.write so evil is that it is only "useful" for scripts inside the body tag that are processed while the page is loading. If document.write is called anytime after page load, it wipes out all the existing page content. That makes it very difficult to dynamically refresh content containing document.write calls.

Fortunately for you, difficult is not impossible, and writeCapture.js has already written (and extensively tested) the difficult part for you. All you have to do is give it the offending evil HTML and it will return nice clean HTML, safe for injection into the document.

Satisfied Customers

  • TheDailyBeast.com uses writeCapture.js.

  • 8tracks.com "We were having horrible latency with our ad providers and your plugin saved the day! Very impressive work!"

If you use writeCapture and want some free advertising, let us know!

Help!

First, please read the wiki, particularly the Options page. There are a lot of workarounds to try before giving up.

Next, ask your question on the mailing list. Please ask your question the smart way. That includes creating a stripped down and working example at http://jsfiddle.net/ so that everyone can play with it. A private page on your site demonstrating the problem is rarely helpful because we can't go and edit the source. Please take the time to reproduce it on JS fiddle so we can help you.

Please do not email the author privately or open an issue in the issue tracker. The author does not actively use write capture, so he probably does not have any idea what is causing your problem.

You may think that it is quicker to go straight to the mailing list or the author without taking the time to isolate the problem and fully read and comprehend the documentation and go over the source code, but anyone who can help you has already done all of those things. Please respect our time, and you will get enthusiastic help.

Caveats/Limitations

  • AdSense - AdSense code using document.write will not work. However AdSense provides asynchronous tracking support, so you don't even need writeCapture to load AdSense asynchronously.

  • If any of the included scripts are on another domain, they will have to be loaded asynchronously via script tag injection. Subsequent scripts in the HTML will be blocked, so order will be preserved, but this means that not all scripts may have yet run after the HTML is injected. This means that if your script depends on all the scripts in the HTML having run, it should utilize the done() callback.

  • Scripts that assume that they are the last element in the document will probably not function properly. This is rare, but if a script is uncouth enough to use document.write, it's a possibility.

Control JS Support

The built in document.write support in Control JS is not great. It adds extra span tags and is not nearly as robust as a full library like writeCapture. That's why writeCapture provides a plugin to replace Control JS's document.write support with writeCapture.js.

For usage, see the wiki.

extsrc Support

extsrc support:

// call from $.ready() or your document ready of choice writeCapture.extsrc(doneCallback);

You can use the same markup (extsrc="...",asyncsrc="...") but with a few advantages:

  • All the power of writeCapture.js, so more document.write edge cases will work.
  • No extra span tags!
  • All scripts with extsrc will be run in order, so you don't have to worry about dependencies.

Note that you do not need extsrc.js, we are simply supporting the same syntax in writeCapture.

Version History

1.0.5

  • Hacks:

    • Updated proxyGetElementById will attempt to copy attributes from the proxy when jQuery is present. Should improve compatibility in some cases.

    • writeOnGetElementById for when proxying isn't enough.

  • New Experimental Feature: autoAsync. Inspired by eligrey's async-document-write.

  • All options and hacks can now be set globally and/or per call.

  • No more eval! Fixes a problem in IE where var variables were not visible to other scripts.

1.0

  • If it's good enough for newsweek.com , it's good enough to be version 1.0.

  • Fixed bug in pause/resume logic when using asyncAll that was preventing execution from resuming.

  • Fixed error in IE when using proxyGetElementById.

0.9.5

  • Big overhaul of the internal queuing system. It should be more robust and 100% deterministic from this point forward. Known to help with deeply nested cross domain scripts.

  • Fixed issue where scripts that include newlines in their src attribute were being truncated.

  • Added debugging support. See support/debug-support.js.

0.9.0

  • writeCapture.js has matured enough to be close to a 1.0 release, after a little seasoning. If you have a problem with your Ad server or other code, submit a bug report!

  • Added hacks to support scripts that combine document.write with DOM manipulation and iframes. Thanks to jcugno for the bug reports and example code. Enabling proxyGetElementById should help with some Ad servers.

0.3.3

  • Fixed a number of issues with 'marginal' scripts (but if all scripts were in good shape, you wouldn't need writeCapture). Should help with some ad servers. Hat tip to neskire for raising the issues.

0.3.2

  • Bugfix - jQuery 1.4.1 has a bug in replaceWith that mishandles strings. We work around it by not using replaceWith.

0.3.1

  • Added fixUrls hack to deal with encoded URLs.

  • Added MIT and GPL licenses, applied retroactively to all versions.

  • Optimized script loading (start loading in parallel immediately) if asyncAll is enabled.

0.3.0

  • Replaced sanitizeAll with sanitizeSerial.

  • Created jQuery plugin.

  • Run all sanitized scripts through a global queue to prevent problems when multiple sanitizes with async loads are run in sequence.

0.2.1

  • Added html and replaceWith convenience methods.

  • Added load convenience method.

0.2.0

  • Only tasks that were running async (read: async script loading with pause/resume) will result in a call to defer.

  • Allowed replacement of support functions by defining writeCaptureSupport so writeCapture can be used without jQuery.

  • Added nolib-support.js for using writeCapture without jQuery.

0.1

  • first release. Any content but a single script tag would result in partially async execution thanks to an overuse of defer.

writecapture's People

Contributors

brewt avatar devdazed avatar iamnoah avatar ironfroggy avatar matthewcieplak avatar stormsilver avatar vincejl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

writecapture's Issues

Having to repeat call to writeCapture twice in order to get ad to render

Hi I'm having to repeat my call to writeCapture in order to get the ad to show up. (Snippet of code below.) If I do not call writeCapture twice, the ad does not show up.

function injectDartScript() {
    wrapper.writeCapture().html(script);
    wrapper.writeCapture().html(script);
}

function init() {
    wrapper = $('#dart-site-banner');

    getCookieParams();
    createDartScript();
    injectDartScript();
}

Problems with scripts that do a document.write and access the written elements

We ran into an issue where an ad was being written with document.write and then tried to access the dom elements written. The writeOnGetElementById option seems to remedy this, but we didn't want to override document.getElementById for performance reasons. What do you guys think of this patch that gives the option to have document.write calls to be written immediately, bypassing the queue?

275c275,276
<       writeOnGet = getOption('writeOnGetElementById',options),  

---
>       writeOnGet = getOption('writeOnGetElementById',options),
>       immediate = getOption('immediateWrites', options),
283,284c284,285
<     doc.write = replacementWrite;
<     doc.writeln = replacementWriteln;

---
>     doc.write = immediate ? immediateWrite : replacementWrite;
>     doc.writeln = immediate ? immediateWriteln : replacementWriteln;
301a303,310
>     }
>     function immediateWrite(s) {
>       var target = $.$(context.target);
>       target.parentNode.innerHTML += s;
>     }
>     function immediateWriteln(s) {
>       var target = $.$(context.target);
>       target.parentNode.innerHTML += s + '\n';

Incompatible with AdSense/DFP?

I'm unable to get any output when using jquery.writeCapture with Google ad tags. I'm using jquery.writecapture head, Chrome 16, Firefox 7, Safari 5.1 Mac.

Test page with 4 slots (at least two of which should populate) here:
http://ny.eater.com/_por.html?google_debug

I the slots populated with div#__document_write_ajax_div-N, but no callback or replacement is made thereafter. In FF console, I see the message "A call to document.write() from an asynchronously-loaded external script was ignored."

I have tried all permutations of $.writeCapture.proxyGetElementById and $.writeCapture.writeOnGetElementById.

Let me know if I can supply any other information. Thanks for the time.

Problem with Firefox.

The following codes work on all major browsers except on Firefox.

$.writeCapture.proxyGetElementById = false;
$.writeCapture.writeOnGetElementById = true;

$("#spotAd1").writeCapture( "html",
"<script type="text/javascript" src="http://partner.googleadservices.com/gampad/google_service.js\">\n" +
"</script><script type="text/javascript">\n" +
"GS_googleAddAdSenseService("ca-pub-5073653240216796");\n" +
"GS_googleEnableAllServices();\n" +
"</script><script type="text/javascript">\n" +
"GA_googleAddSlot("ca-pub-5073653240216796", "FullBanner_Custom_Bot_HomePage");\n" +
"</script><script type="text/javascript">\n" +
"GA_googleFetchAds();\n" +
"</script>\n" +
"\n" +
"<script type="text/javascript">\n" +
"GA_googleFillSlot("FullBanner_Custom_Bot_HomePage");\n" +
"</script>\n" +
"\n" );

It must display an ad but when I load it using Firefox, two errors came up:

  1. uncaught exception: [Exception... "Illegal operation on WrappedNative prototype object" nsresult: "0x8057000c (NS_ERROR_XPC_BAD_OP_ON_WN_PROTO)" location: "JS frame :: http://partner.googleadservices.com/gampad/google_ads.js :: anonymous :: line 74" data: no]
    [Break on this error](no source for)
  2. window.document_write_ajax_callbacks is undefined

Can you please help me to figure out what wrong in here?

I'm using the jquery.writeCapture-1.0.5-min.js file.

Does not emulate document.write properly with Rich Ads

I have rich doubleclick advertisement and WC2 is almost completely broken when working with it.

To have this ad I should insert a script element into the page (asynchronously, after page load).
Like this

<script type="text/javascript" src="http://ad.doubleclick.net/adj/csn.ne/home;pos=1;sz=300x250;genre=sport;category=csnsports;tile=3;atf=y;type=homepage;ucid=homepage;sect=homepage;ord=1347409260?"></script>

I don't know if this URL will be alive when you will start investigating the issue.
This script contents are following:

document.write('\x3cobject classid\x3d\x22clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\x22id\x3d\x22google_flash_obj\x22height\x3d\x22250\x22width\x3d\x22300\x22\x3e\x3cparam name\x3dMOVIE value\x3d\x22http://pagead2.googlesyndication.com/pagead/imgad?id\x3dCICAgICQw8uyPBCsAhj6ATII-pOyoEy8v1A\x22\x3e\x3cparam name\x3dquality value\x3dhigh\x3e\x3cparam name\x3d\x22AllowScriptAccess\x22 value\x3d\x22never\x22\x3e\x3cparam name\x3d\x22wmode\x22 value\x3d\x22opaque\x22\x3e\x3cparam name\x3d\x22FlashVars\x22 value\x3d\x22clickTAG\x3dhttp://googleads.g.doubleclick.net/aclk%3Fsa%3DL%26ai%3DBwdOl9hnBUJm8I6HO0AGs2YDgAsCUtLsEAAAAEAEgADgAUL_v3ZIBWKCxwtFeYMm-8Yq0pNgPggEXY2EtcHViLTAxMDM4MTgyNzE3MTc5MTKyASBjc25uZWRldi5uYmNzcG9ydHMuYWNxdWlhLXBzLmNvbboBCWdmcF9pbWFnZcgBBNoBKGh0dHA6Ly9jc25uZWRldi5uYmNzcG9ydHMuYWNxdWlhLXBzLmNvbS_AAgLgAgDqAhA2MDAzL2Nzbi5uZS9ob21l-AKC0h6QA6QDmAOkA6gDAdAEkE7gBAGgBhU%26num%3D0%26sig%3DAOD64_1v9-LjOzEXL-fBwjaMJLH61e4UtQ%26client%3Dca-pub-0103818271717912%26adurl%3Dhttp://www.business.comcast.com/\x22\x3e\x3cobject data\x3d\x22http://pagead2.googlesyndication.com/pagead/imgad?id\x3dCICAgICQw8uyPBCsAhj6ATII-pOyoEy8v1A\x22id\x3d\x22google_flash_embed\x22width\x3d\x22300\x22height\x3d\x22250\x22wmode\x3d\x22opaque\x22FlashVars\x3d\x22clickTAG\x3dhttp://googleads.g.doubleclick.net/aclk%3Fsa%3DL%26ai%3DBwdOl9hnBUJm8I6HO0AGs2YDgAsCUtLsEAAAAEAEgADgAUL_v3ZIBWKCxwtFeYMm-8Yq0pNgPggEXY2EtcHViLTAxMDM4MTgyNzE3MTc5MTKyASBjc25uZWRldi5uYmNzcG9ydHMuYWNxdWlhLXBzLmNvbboBCWdmcF9pbWFnZcgBBNoBKGh0dHA6Ly9jc25uZWRldi5uYmNzcG9ydHMuYWNxdWlhLXBzLmNvbS_AAgLgAgDqAhA2MDAzL2Nzbi5uZS9ob21l-AKC0h6QA6QDmAOkA6gDAdAEkE7gBAGgBhU%26num%3D0%26sig%3DAOD64_1v9-LjOzEXL-fBwjaMJLH61e4UtQ%26client%3Dca-pub-0103818271717912%26adurl%3Dhttp://www.business.comcast.com/\x22type\x3d\x22application/x-shockwave-flash\x22AllowScriptAccess\x3d\x22never\x22\x3e\x3cdiv align\x3d\x22center\x22\x3e\x3ca href\x3d\x22http://googleads.g.doubleclick.net/aclk?sa\x3dL\x26amp;ai\x3dBwdOl9hnBUJm8I6HO0AGs2YDgAsCUtLsEAAAAEAEgADgAUL_v3ZIBWKCxwtFeYMm-8Yq0pNgPggEXY2EtcHViLTAxMDM4MTgyNzE3MTc5MTKyASBjc25uZWRldi5uYmNzcG9ydHMuYWNxdWlhLXBzLmNvbboBCWdmcF9pbWFnZcgBBNoBKGh0dHA6Ly9jc25uZWRldi5uYmNzcG9ydHMuYWNxdWlhLXBzLmNvbS_AAgLgAgDqAhA2MDAzL2Nzbi5uZS9ob21l-AKC0h6QA6QDmAOkA6gDAdAEkE7gBAGgBhU\x26amp;num\x3d0\x26amp;sig\x3dAOD64_1v9-LjOzEXL-fBwjaMJLH61e4UtQ\x26amp;client\x3dca-pub-0103818271717912\x26amp;adurl\x3dhttp://www.business.comcast.com/\x22 target\x3d\x22_blank\x22\x3e\x3cimg src\x3d\x22http://pagead2.googlesyndication.com/pagead/imgad?id\x3dCICAgICQw8vC-AEQrAIY-gEyCAazRB7q3d56\x22height\x3d\x22250\x22width\x3d\x22300\x22/\x3e\x3c/a\x3e\x3c/div\x3e\x3c/object\x3e\x3c/object\x3e');

Problem 1
What WC2 does is it inserts all 3 elements which are present in document.write into the page (like this: http://i.imgur.com/baolK.png) because it is TOO smart.

If you execute this code manually in javascript console the actual result will be just ONE element, like this http://i.imgur.com/HgvJ0.png

But that's not the only problem.

Problem 2
Another problem is that URL where Ad should link to is broken because &amp; does not get translated into the & when this script tag is being added to the page via

writeCapture.write(target_element, '<script type="text/javascript" src="http://ad.doubleclick.net/adj/csn.ne/home;pos=1;sz=300x250;genre=sport;category=csnsports;tile=3;atf=y;type=homepage;ucid=homepage;sect=homepage;ord=1347409260?"></script>')

How Do I Install This Plugin?

Hi,

I'm trying to install this plugin, but every test install I do fails to trigger an using the test code from the "Usage" page and I cannot find any installation instructions anywhere. I need this plugin to load my AdBrite ads because putting the code on a lone html document and writing an Iframe to the main page onready causes some ads to break and render partially if not completely below the framed part of the other document in IE 7 & IE 8 even if I make the frame larger than 728x90 for a leaderboard.

So far I've tried including jQuery, WriteCapture, and the latest jQuery plugin for write capture in various configurations such as:

<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.6.4.min.js"></script>
<script type="text/javascript" src="http://mysite.com/js/writeCapture.js"></script>
<script type="text/javascript" src="http://mysite.com/js/jquery.writeCapture-1.0.5-min.js"></script>
<script type="text/javascript" src="http://mysite.com/js/testwritecapture.js"></script>

I've also tried:

<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.6.4.min.js"></script>
<script type="text/javascript" src="http://mysite.com/js/jquery.writeCapture-1.0.5-min.js"></script>
<script type="text/javascript" src="http://mysite.com/js/testwritecapture.js"></script>

I would go on, but that is basically all I've tried so far and I can't think of any reason why the plugin does not respond at all. In both cases the file testwritecapture.js contains the following code copied from your "Usage" page which should trigger an alert once loaded:

$.writeCapture.autoAsync(function () {
alert('Ads loaded!'); // don't do this though, it would be annoying
});

I have yet to see a single alert. I must admit that I am a little lost when it comes to JavaScript because I'm primarily a C# programmer who works within the ASP.Net framework, so usually I just have to drag and drop a control before using server side code to do everything I need. I'm only messing with JavaScript because I want ads to load quicker.

Ads not respecting destination div#id and loading in the wrong place

Summary of issue

I've been attempting to implement your script however no matter which way I try and do so I always seem to get the ads loading in the wrong target id. Do you have any ideas about where I might be getting things wrong? This happens no matter whether I do inline scripts or use a document.ready.

Example

<div id="ad-1"></div>
<script language="javascript" type="text/javascript">       
  $('#ad-1').writeCapture().html('<scr'+'ipt type="text/javascript" src="script url"><'+'/script>').end();
</script>   

<div id="ad-2"></div>
<script language="javascript" type="text/javascript">           
  $('#ad-2').writeCapture().html('<scr'+'ipt type="text/javascript" src="script url"><'+'/script>').end();
</script>           

<div id="ad-3"></div> 
<script language="javascript" type="text/javascript">       
  $('#ad-3').writeCapture().html('<scr'+'ipt type="text/javascript" src="script url"><'+'/script>').end();
</script>       

Any help with this is appreciated, it looks like I'm getting the exact same results no matter what browser I'm using.

$ shortcut should not be used in jQuery plugins

Because jQuery may be used in no conflict mode the $ shortcut may not be assigned to jQuery. in jquery.writecapture.js and writecapture.js all references to $ should be replaced with jQuery to ensure the plugin works in no conflict environments.

document.getElementById

Running into a situation with an ad script doing the following:

var divid='dclkAdsDivID_6302';
document.write('

');
var iframe_6302=document.createElement('iframe');
iframe_6302.id='dclkAdsFrameID_6302';
iframe_6302.name='dclkAdsFrameName_6302';
iframe_6302.src="about:blank";
iframe_6302.scrolling="no";
iframe_6302.width=728;
iframe_6302.height=90;
iframe_6302.frameborder=0;
iframe_6302.style.border=0;
iframe_6302.allowtransparency="true";
iframe_6302.hspace=0;
iframe_6302.vspace=0;
iframe_6302.marginHeight=0;
iframe_6302.marginWidth=0;
var parent_6302 = document.getElementById(divid);
parent_6302.appendChild(iframe_6302);

The problem is that document.getElementById on the new div that was just placed with document.write (and is just part of state.out) is going to return undefined since the DOM doesn't have this new div yet.

Wondering what your thoughts on this are?

Ajax callbacks not firing properly

When loading ads in, I'm often left with the following trailing text node:
window['document_write_ajax_callbacks']'50';

Any idea of where I could start even looking to hack in a fix?

uncaptured document.write?

This may be unsolvable, but I thought I would mention it.

I have a page that loads an ad, google analytics and a nielsen tracking beacon. I'm trying writecapture on the ad, but I'm running into the document.write('') blank screen in FF. I'm not seeing it in chrome at the moment.
http://retro.bb-ref.org/players/j/jeterde01.shtml

Here is the jquery code i'm using.

var ad300 = '<SCRIPT type="text/javascript">\n    <!--\n    var randomNumber = Math.floor(Math.random()*9999999999+1);\n    document.write(\'<scr\' + \'ipt src=http://ad.doubleclick.net/adj/baseballreference.fsv/ros;sect=ros;fantasy=no;game=no;tile=3;sz=300x250;ord=\' + random_number + \'?></scr\' + \'ipt>\');\n// -->\n</SCRIPT>\n';
$('#fm300x250').html($.writeCapture.sanitize(ad300,function() { }));

When this runs in FF I sometimes get the blank screen and here is the response that causes it.

document.write('');

admeld_publisher  = 195;
admeld_site       = 'fsv';
admeld_size       = '300x250';
admeld_placement   = 'ros';
// do not change below

document.write('<scrip'+'t type="text/javascript" src="http://tag.admeld.com/ad/js/' +
admeld_publisher + '/' +
admeld_site + '/' +
admeld_size +'/' +
admeld_placement +
'?url=' + escape(document.referrer) +
'"></scrip'+'t>');

document.write('');

This sets off a cascade of document.writes as we run through a half dozen different js scripts to generate the page.

// here is the first.
document.write(unescape('%3C%21--%20%20Rubicon%20Project%20tag%20--%3E%0A%3C%21--%20%20Site%3A%20Fantasy%20Sports%20Ventures%20%28Safe%29%20%20%20Zone%3A%20My%20Site%20%20%20Size%3A%20Medium%20Rectangle%20%20--%3E%0A%3Cscript%20language%3D%22JavaScript%22%20type%3D%22text%2Fjavascript%22%3E%0Avar%20cb%20%3D%20Math.random%28%29%3B%0Avar%20d%20%3D%20document%3B%0Ad.write%28%27%3Cscript%20language%3D%22JavaScript%22%20type%3D%22text%2Fjavascript%22%27%29%3B%0Ad.write%28%27src%3D%22http%3A%2F%2Foptimized-by.rubiconproject.com%2Fa%2F5941%2F7885%2F13253-15.js%3Fcb%3D%27%2Bcb%2B%27%22%3E%27%29%3B%0Ad.write%28%27%3C%5C%2Fscr%27%2B%27ipt%3E%27%29%3B%0A%3C%2Fscript%3E'));

any help would be greatly appreciated. These damn ads cause the site to hang every once and awhile I'm pretty sure they are driving down pages/visit pretty substantially. My next option is loading them in the footer and moving them.

getElementById() failing

Hi, great plugin!

I'm testing this plugin in an environment where small 3rd party JS advertising scripts use document.write()s to embed their advertising. It worked pretty well right off-the-bat for generic ads, but I found an important use-case where its failing for me.

It fails when it receives the following 3rd-party javascript from our ad network:

=============================

1|
2| document.write('');
3|
4| var strRand = "rand" + parseInt(Math.random() * 100000);
5| document.write("<di_v id="" + strRand + ""></d_iv>");
6| document.getElementById(strRand).parentNode.className = "adServer taEmpty";
7|
8| document.write('\n<img class="emptySlug" src="http://s0.2mdn.net/1878259/1x1_spacer.gif\" width="1" height="1" border="0">');
9|

(*Ignore the underscores in the div tag, this was for display purposes only)

==============================

When the JS parser makes it to the getElementById call on line 6, it fails to find the 'strRand' element and throws an exception. This is because 'strRand' is defined in line 5, however, it appears that writeCapture() stores all the HTML sent to document.write() until the script is fully parsed and then writes it to the document. This means 'strRand' won't be available for lookup until after execution of this script yet it is needed midst execution.

I noticed writeCapture.js has a getElementById proxy method... do you already have a way that this type of case can be made to work?

NOTE: I'm using the most recent version of writeCapture, version 1.0.0 (looks like you just updated it 5 hours ago)

Cheers, and thanks in advance :D
Luke

document.createElement AND document.getElementById

I've got a script that uses document.createElement and then applies attributes and HTML to the element. However, I think that later on it also relied on getElementById (via the proxy) to change this element. When a script works like this, could the resulting element be incorrect?

FYI - I'm testing with the Twitter Profile widget at http://twitter.com/goodies/widget_profile, and trying to insert this dynamically into a page.

Thanks for any help you can provide here!

Simon

Using writeCapture to change ads through a gallery

Hi,

I'm trying to use your writeCapture library, so when I click to the next image my div with the ads refresh, except they also display every ad in the cycle.

My test js being used in the console:

var innerhtml = jQuery('#sidebar_ad').html();
jQuery('#sidebar_ad').writeCapture().html(innerhtml);

Again, this does refresh the ads, but instead of displaying 2 ads, which is what it's supposed to do, it displays 8 ads, which are all part of that cycle.

The ads can be viewed on the right rail at: http://stage.youbeauty.com/hair/galleries/celebrities-with-black-hair

Except the plugin is not yet on that site, only on my local site.

Any ideas/help would be appreciated.

Thanks,
Oren

In safari 5.1 writeCapture dosent work properly

Hello,
My code working in almost any browser including IE7,8,9 (forget about IE6).
Js & html code is on same domain still its not working.
Every time it returns me blank div <div style='margin:0px;padding:0px;border:none;' id='atm_div_0.6820882398169488'></div>.
But if I change referrer by developer tool to any other browser then it works perfectly fine.
Can you please tell me whats the problem.

Problem with writeCapture + Pointroll ads

Great library, it's the only solution that's even come close to serving all DFP ads properly. Having a problem with one Pointroll ad though - here's a sample page I put up that shows the issue:

http://jeka.co/test/pointroll.php

Looks like everything goes through and even the ad that's supposed to go through gets downloaded but it never shows up and the div ends up being empty. Do you have any idea what the problem may be? Tried all the options, etc. This occurs with both jquery and non-jquery versions.

Funny thing - that pointroll ad worked with my basic homebrew solution (capture document.write into buffer, preg match script tags, execute each) and worked with bezen solution (similar idea, more evolved) but doesn't work with writeCapture - whereas writeCapture is able to handle all the other insane ads that bezen and homebrew failed on.

Any ideas?

Wait to finish before next capture?

Is there anyway to queue captures?

Or let me ask like this:

Is there any possibly way actually make two or more writeCaptures do their job to wait until previous capture finished...

writeCapture.proxyGetElementById = true; failing on ie6 and ie7

The offending line seems to be:
var result = state.getEl.call(global.document,id);

It seems that IE host objects are not proper JavaScript objects in ie6 and ie7 and cannot be modified with the .call() method.

The error that IE throws is "Object doesn't support this property or method".

Repeating the same code

I'm having problems capturing the same code dynamically more than once. That is, if I writeCapture some script tags once, they work OK, but if I try to writeCapture the identical script tags again then I get a blank output...

I've tried this with several different scripts, and it seems to be an issue with the writeCapture, rather than the scripts themselves. The scripts all work with writeCapture once successfully.

The context of this issue is that we allow users to paste in code within a page in BaseKit. They can edit the code live in a textarea, and when they click save it passes the contents through writeCapture again and injects the sanitized output into the page. This works once but if I click save again, then the content is lost.

Is there any way to clear writeCapture to enable it to capture the same script twice?

Thanks,
Simon @ BaseKit

Ad fails in IE with writeCapture

I've been banging my head for a couple hours trying to debug this one, but haven't gotten anywhere. I hope someone can help with this. I have a "simple" example here:

http://jsfiddle.net/Nn5pR/2/
http://jsfiddle.net/9qQSP/ (no writeCapture)

In Firefox, you get the green IBM Flash ad, but in IE (all versions), you don't get anything. I'm leaning towards this being a problem with the way the ad code works, but would love to see a work around in writeCapture.

It seems to do everything right until right before it loads the actual swf file.

Any ideas? Thanks!

Adrian

doXDomainLoad fails to make a network request

This has been suggested as a slightly ridiculous error case. It's several requests to sanitize a single div (ad rotator) in rapid succession. In response to this mistreatment, writeCapture promptly dies.

To reproduce:

  1. Go to http://www.wsbtv.com/gallery/news/10-year-old-mauled-dogs/gGGk/#660698
  2. Double click on the next or prev arrows for the gallery or on one of the photos.
  3. Ads are not displayed. This is the writecapture call in question: https://github.com/coxmediagroup/marimo/blob/master/lib/marimo.js#L431

Weird firefox bug with getJson

I noticed that Firefox 3.6.13 (mine is Ubuntu 10.10, but this should be a platform independent bug) has a really weird issue with writeCapture.

Compare these really easy two testcases. The first one is broke, the other one works. The only difference between them is an emty javascript file that is loaded at the end of the page. If i comment it out, it startst to work. There is really no difference if this file is empty or not. It won't work anyway.

http://f.postimees.ee/test/ (broke - content appears at the bottom)
http://f.postimees.ee/test/works.html (works)

Other browser do not have this issue.

Using proxyGetElementById or writeOnGetElementById does not make any difference.

Dynamically added Javascript not deploying in IE

Hi,

I'm trying to dynamically add ads that contain some Javascript. It works great in Firefox, Safari and Chrome but the added javascript in the snippet doesn't seem to be deploying in Internet Explorer 7 and 8.

Here's what I'm doing:

                     jQuery(".location").each(function() {
                                jQuery(this).replaceWith(writeCapture.sanitize(retrieved_ad));
                            });

Here's a sample of the value that retrieved_ad can have:

<div class="advertisement"> <!-- Begin: AdBrite, Generated: 2010-01-18 12:05:49 --> <script type="text/javascript"> var AdBrite_Title_Color = '0000FF'; var AdBrite_Text_Color = '000000'; var AdBrite_Background_Color = 'FFFFFF'; var AdBrite_Border_Color = 'CCCCCC'; var AdBrite_URL_Color = '008000'; try{var AdBrite_Iframe=window.top!=window.self?2:1;var AdBrite_Referrer=document.referrer==''?document.location:document.referrer;AdBrite_Referrer=encodeURIComponent(AdBrite_Referrer);}catch(e){var AdBrite_Iframe='';var AdBrite_Referrer='';} </script> <script type="text/javascript">document.write(String.fromCharCode(60,83,67,82,73,80,84));document.write(' src="http://ads.adbrite.com/mb/text_group.php?sid=1439121&zs=3330305f323530&ifr='+AdBrite_Iframe+'&ref='+AdBrite_Referrer+'" type="text/javascript">');document.write(String.fromCharCode(60,47,83,67,82,73,80,84,62));</script> <div><a href="http://foobar.com/www/delivery/ck.php?oaparams=2__bannerid=138__zoneid=21__source=bgV%3Db3RoZXI%3D%2CbtA%3DMTAwMDAwOTI%3D%2CJsR%3D941160000%2CyEr%3DCA%2CbcB%3DYWRtaW4%3D__cb=10000016:10000092:ffafed06f6__oadest=http://www.adbrite.com/mb/commerce/purchase_form.php?opid=1439121&afsid=1" style="font-weight:bold;font-family:Arial;font-size:13px;" target="_blank">Your Ad Here</a></div> <!-- End: AdBrite --><div id='beacon_ffafed06f6' style='position: absolute; left: 0px; top: 0px; visibility: hidden;'><img src='http://foobar.com/www/delivery/lg.php?bannerid=138&amp;campaignid=38&amp;zoneid=21&amp;source=bgV=b3RoZXI=,btA=MTAwMDAwOTI=,JsR=941160000,yEr=CA,bcB=YWRtaW4=&amp;loc=1&amp;referer=http%3A%2F%2Fjchung.dev.foobar.com%2Fad%2Fapi%2Fget_ad%3Fz%3D21&amp;cb=ffafed06f6' width='0' height='0' alt='' style='width: 0px; height: 0px;' /></div> </div>

I'm using writeCapture-1.0.0-nolib-min.js.

Is there something I'm missing?

Thanks!

Problem in safari browsers & problem in working with writeCapture 2

Hello Noah,
I have submitted you #48 before, saying writeCapture gives problem while working with safari browsers .Didn't get any reply there after posting my jsfiddel demo , so created new issue.
I have found out that if ad is iframe like survey form etc then it gives problem else if ad is just a banner then it works fine.
You suggested me to use writecapture 2 , but still I am not able to make it work.
I am giving you links of jsfiddel ,
writeCapture 2 demo - http://jsfiddle.net/CBTuC/
writeCature demo which do not work in safari - http://jsfiddle.net/sZaCF/8/

el is undefined when calling the function before currents adds have finished

Hi there.

Just wondering if you've ever come across 'el is undefined' error before?

The only way i recreate this error is call the function and then calling it again before the adds have finished loading from the first call.

Heres my code, this code runs each time :
ajaxAds.changeAds = function (){
//Remove Current Adds
$('#banner').empty();

  var str_html_banner = tmgAdsBuildAdTag("ban", "728x90,468x60", "adj", "", 2);
  $('#banner').html(writeCapture.sanitize(str_html_banner));

}

While i'll write something on my end to wait until everything has loaded i just wondered if there was anything you're aware of that might do this?

Again cheers for making this fully sexy plug-in :)

TypeError in replaceWith (nolib-support.js)

Uncaught TypeError: Cannot read property 'parentNode' of null

Tested in Firefox 3.6 and Chrome 13

writeOnGetElementById seems to fix this but only if the call to writeCapture.html is not made from within a table.

document.write('<!-- Copyright 2008 DoubleClick, a division of Google Inc. All rights reserved. -->\r\n<!-- Code auto-generated on Wed Aug 17 00:56:46 EDT 2011 -->\r\n<script src=\"http://s0.2mdn.net/879366/flashwrite_1_2.js\"><\/script>');document.write('\r\n');

function DCFlash(id,pVM){
var swf = "http://s0.2mdn.net/1540282/Tribeca_Snow_300x250.swf";
var gif = "http://s0.2mdn.net/1540282/Tribeca_Snow_300x250.jpg";
var minV = 8;
var FWH = ' width="300" height="250" ';
var url = escape("http://ad.au.doubleclick.net/6k%3Bh%3Dv8/3b7c/3/0/%2a/m%3B245013661%3B0-0%3B0%3B69607616%3B4307-300/250%3B43590106/43607893/1%3Bu%3Dpos%3D1%2Cpagetype%3Dindex%3B%7Eaopt%3D0/ff/27/ff%3B%7Efdr%3D244965911%3B0-0%3B2%3B28037886%3B4307-300/250%3B43590502/43608289/1%3Bu%3Dpos%3D1%2Cpagetype%3Dindex%3B%7Eokv%3D%3Bsec1%3Dtest%3Btile%3D3%3Bpos%3D1%3B%3Bsz%3D300x250%3Bkw%3Dnews%2Cworld%2Casia%3Bk%3Dv%3Bu%3Dpos%3D1%2Cpagetype%3Dindex%3B%7Eaopt%3D2/1/27/2%3B%7Esscs%3D%3fhttp://subaru.com.au/tribeca?utm_source=display&utm_medium=display&utm_campaign=brand_tribeca");
var fscUrl = url;
var fscUrlClickTagFound = false;
var wmode = "opaque";
var bg = "";
var dcallowscriptaccess = "never";

var openWindow = "false";
var winW = 0;
var winH = 0;
var winL = 0;
var winT = 0;

var moviePath=swf.substring(0,swf.lastIndexOf("/"));
var sm=new Array();


var defaultCtVal = escape("http://ad.au.doubleclick.net/6k%3Bh%3Dv8/3b7c/3/0/%2a/m%3B245013661%3B0-0%3B0%3B69607616%3B4307-300/250%3B43590106/43607893/1%3Bu%3Dpos%3D1%2Cpagetype%3Dindex%3B%7Eaopt%3D0/ff/27/ff%3B%7Efdr%3D244965911%3B0-0%3B2%3B28037886%3B4307-300/250%3B43590502/43608289/1%3Bu%3Dpos%3D1%2Cpagetype%3Dindex%3B%7Eokv%3D%3Bsec1%3Dtest%3Btile%3D3%3Bpos%3D1%3B%3Bsz%3D300x250%3Bkw%3Dnews%2Cworld%2Casia%3Bk%3Dv%3Bu%3Dpos%3D1%2Cpagetype%3Dindex%3B%7Eaopt%3D2/1/27/2%3B%7Esscs%3D%3fhttp://subaru.com.au/tribeca?utm_source=display&utm_medium=display&utm_campaign=brand_tribeca");
var ctp=new Array();
var ctv=new Array();
ctp[0] = "clickTag";
ctv[0] = "";


var fv='"moviePath='+moviePath+'/'+'&moviepath='+moviePath+'/';
for(i=1;i<sm.length;i++){if(sm[i]!=""){fv+="&submovie"+i+"="+escape(sm[i]);}}
for(var ctIndex = 0; ctIndex < ctp.length; ctIndex++) {
  var ctParam = ctp[ctIndex];
  var ctVal = ctv[ctIndex];
  if(ctVal != null && typeof(ctVal) == 'string') {
    if(ctVal == "") {
      ctVal = defaultCtVal;
    }
    else {
      ctVal = escape("http://ad.au.doubleclick.net/6k%3Bh%3Dv8/3b7c/3/0/%2a/m%3B245013661%3B0-0%3B0%3B69607616%3B4307-300/250%3B43590106/43607893/1%3Bu%3Dpos%3D1%2Cpagetype%3Dindex%3B%7Eaopt%3D0/ff/27/ff%3B%7Efdr%3D244965911%3B0-0%3B2%3B28037886%3B4307-300/250%3B43590502/43608289/1%3Bu%3Dpos%3D1%2Cpagetype%3Dindex%3B%7Eokv%3D%3Bsec1%3Dtest%3Btile%3D3%3Bpos%3D1%3B%3Bsz%3D300x250%3Bkw%3Dnews%2Cworld%2Casia%3Bk%3Dv%3Bu%3Dpos%3D1%2Cpagetype%3Dindex%3B%7Eaopt%3D2/1/27/2%3B%7Esscs%3D%3f" + ctVal);
    }
    if(ctParam.toLowerCase() == "clicktag") {
      fscUrl = ctVal;
      fscUrlClickTagFound = true;
    }
    else if(!fscUrlClickTagFound) {
      fscUrl = ctVal;
    }
    fv += "&" + ctParam + "=" + ctVal;
  }
}
fv+='"';
var bgo=(bg=="")?"":'<param name="bgcolor" value="#'+bg+'">';
var bge=(bg=="")?"":' bgcolor="#'+bg+'"';
function FSWin(){if((openWindow=="false")&&(id=="DCF0"))alert('openWindow is wrong.');
var dcw = 800;
var dch = 600;
// IE
if(!window.innerWidth)
{
  // strict mode
  if(!(document.documentElement.clientWidth == 0))
  {
    dcw = document.documentElement.clientWidth;
    dch = document.documentElement.clientHeight;
  }
  // quirks mode
  else if(document.body)
  {
    dcw = document.body.clientWidth;
    dch = document.body.clientHeight;
  }
}
// w3c
else
{
  dcw = window.innerWidth;
  dch = window.innerHeight;
}
if(openWindow=="center"){winL=Math.floor((dcw-winW)/2);winT=Math.floor((dch-winH)/2);}window.open(unescape(fscUrl),id,"width="+winW+",height="+winH+",top="+winT+",left="+winL+",status=no,toolbar=no,menubar=no,location=no");}this.FSWin = FSWin;
ua=navigator.userAgent;
if(minV<=pVM&&(openWindow=="false"||(ua.indexOf("Mac")<0&&ua.indexOf("Opera")<0))){
    var adcode='<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" id="'+id+'"'+FWH+'>'+
        '<param name="movie" value="'+swf+'"><param name="flashvars" value='+fv+'><param name="quality" value="high"><param name="wmode" value="'+wmode+'"><param name="base" value="'+swf.substring(0,swf.lastIndexOf("/"))+'"><PARAM NAME="AllowScriptAccess" VALUE="'+dcallowscriptaccess+'">'+bgo+
        '<embed src="'+swf+'" flashvars='+fv+bge+FWH+' type="application/x-shockwave-flash" quality="high" swliveconnect="true" wmode="'+wmode+'" name="'+id+'" base="'+swf.substring(0,swf.lastIndexOf("/"))+'" AllowScriptAccess="'+dcallowscriptaccess+'"></embed></object>';
  if(('j'!="j")&&(typeof dclkFlashWrite!="undefined")){dclkFlashWrite(adcode);}else{document.write(adcode);}
}else{
    document.write('<a target="_blank" href="'+unescape(url)+'"><img src="'+gif+'"'+FWH+'border="0" alt="Advertisement" galleryimg="no"></a>');
}}
var pVM=0;var DCid=(isNaN("245013661"))?"DCF2":"DCF245013661";
if(navigator.plugins && navigator.mimeTypes.length){
  var x=navigator.plugins["Shockwave Flash"];if(x && x.description){var pVF=x.description;var y=pVF.indexOf("Flash ")+6;pVM=pVF.substring(y,pVF.indexOf(".",y));}}
else if (window.ActiveXObject && window.execScript){
  window.execScript('on error resume next\npVM=2\ndo\npVM=pVM+1\nset swControl = CreateObject("ShockwaveFlash.ShockwaveFlash."&pVM)\nloop while Err = 0\nOn Error Resume Next\npVM=pVM-1\nSub '+DCid+'_FSCommand(ByVal command, ByVal args)\nCall '+DCid+'_DoFSCommand(command, args)\nEnd Sub\n',"VBScript");}
eval("function "+DCid+"_DoFSCommand(c,a){if(c=='openWindow')o"+DCid+".FSWin();}o"+DCid+"=new DCFlash('"+DCid+"',pVM);");
//-->

document.write('\r\n<noscript><a target=\"_blank\" href=\"http://ad.au.doubleclick.net/6k%3Bh%3Dv8/3b7c/3/0/%2a/m%3B245013661%3B0-0%3B0%3B69607616%3B4307-300/250%3B43590106/43607893/1%3Bu%3Dpos%3D1%2Cpagetype%3Dindex%3B%7Eaopt%3D0/ff/27/ff%3B%7Efdr%3D244965911%3B0-0%3B2%3B28037886%3B4307-300/250%3B43590502/43608289/1%3Bu%3Dpos%3D1%2Cpagetype%3Dindex%3B%7Eokv%3D%3Bsec1%3Dtest%3Btile%3D3%3Bpos%3D1%3B%3Bsz%3D300x250%3Bkw%3Dnews%2Cworld%2Casia%3Bk%3Dv%3Bu%3Dpos%3D1%2Cpagetype%3Dindex%3B%7Eaopt%3D2/1/27/2%3B%7Esscs%3D%3fhttp://subaru.com.au/tribeca?utm_source=display&utm_medium=display&utm_campaign=brand_tribeca\"><img src=\"http://s0.2mdn.net/1540282/Tribeca_Snow_300x250.jpg\" width=\"300\" height=\"250\" border=\"0\" alt=\"Advertisement\" galleryimg=\"no\"></a></noscript>\r\n');

Fails with <script foo="bar"src="baz">

writeCapture fails if the script has non space before the src attribute. this is probably incorrect behaviour on this publisher's part, but this maybe something writecapture could work around.

I modified attrPattern to

    function attrPattern(name) {
        return new RegExp('[\\s\\r\\n]?'+name+'=(?:(["\'])([\\s\\S]*?)\\1|([^\\s>]+))','i');
    }

Fix for wrong detection of type attribute

Firstly, thanks for your efforts with this plugin - it's been really useful!

I was trying to use it with the following script tag - a Google Gadget - but there were problems when doing this dynamically (the script tag was skipped, therefore the contained document.write kicked in and the page was nuked):

<script src="http://www.gmodules.com/ig/ifr?url=http://digg.com/goog/ig.xml&amp;up_user=&amp;up_thumbnail=1&amp;up_filter=0&amp;up_num=5&amp;up_type=popular&amp;up_refresh=0&amp;up_tab=0&amp;up_offset=0&amp;up_pagination=0&amp;up_business=true&amp;up_entertainment=true&amp;up_gaming=true&amp;up_lifestyle=true&amp;up_offbeat=true&amp;up_politics=true&amp;up_science=true&amp;up_sports=true&amp;up_technology=true&amp;up_world_news=true&amp;synd=open&amp;w=320&amp;h=200&amp;title=Digg&amp;border=%23ffffff%7C3px%2C1px+solid+%23999999&amp;output=js"></script>

I investigated, and the problem was that the URL parameter "up_type=popular" was regex matched as the type attribute of the script tag. The code was therefore detecting this as non-Javascript and skipping the write capturing.

To fix this I've added a space before the attribute name in the attrPattern function:

return new RegExp('\\s' + name + '=(?:(["\'])([\\s\\S]*?)\\1|([^\\s>]+))','i');

Hope this helps!

Simon @ BaseKit

Two ads on a page causing type error

Hello,

Thanks for making this super helpful library. I am running into a bit of a weird issue.

When I have two ads on a page and run write capture I am getting a Uncaught TypeError: Object # has no method '2' and Uncaught TypeError: Object # has no method '3' with the following stack output

globalEval
reffering to - head.insertBefore( script, head.firstChild );

global.writeCaptureSupport.replaceWith
reffering to - globalEval(scripts[i]);

html
reffering to - $.replaceWith(context.target,sanitize(markup,safeOpts(options),queue,context) + (cb || ''));

captureAndResume
reffering to - html(uncapture(state),

script.onload.script.onreadystatechange
reffering to - success();

I am using the no-lib library with the tool. I have also tried with the jquery plugin and I am getting the same error. If I switch the order of the ads, the first one will always run and the second one will always fail. If I call the ads by themselves, both will load with writecapture but when both are present only 1 will load.

The writecapture code is being called like so
function(settings){
console.log(settings)
var adsrc = dartAdSettings.createDartTag(settings);
var adhtml = '<script language="JavaScript" src="'+adsrc+'" type="text/javascript"></script>'
writeCapture.proxyGetElementById = true;
//writeCapture.writeOnGetElementById = true; I have tried with and without this it makes no difference.
writeCapture.html("#"+settings["id"],adhtml)
}

Thanks for your help,
CG

paying attention to <script> attrs

Howdy,

I'm having to work with some ads javascript that does this cute trick (summarized):

document.write('<script id="foo"></script><script>setTimeout('document.getElementById("foo").src="some_more_ad_stuff.js"', 1)</script>')

writeCapture, as far as I'm concerned, is not doing anything wrong here--<script> tags are not supposed to use any of the standard attributes (like id). But because the <script>s in the doc.write don't ever get added to the dom the ads break.

I'm working on a patch now to support their behavior, and thought I'd bring it up here in case there was already a good workaround for shenanigans like this.

(I can submit whatever I come up with, but understand that supporting every wicked whim of various ad vendors is not a feature of writecapture).

thanks,
Nathaniel

Doubleclick 3rd party Flash Ads don't show up

I'm trying to use the plugin like this (see below), but after document ready I see white screen which constantly load something (looks like document.write was not captured or something):

Could you please take a look at that sample when you get a sec? That ad call should work for a while.

var sampleCode = '<script language="JavaScript" src="http://ad.doubleclick.net/adj/mansueto.fcmba/homepage;sz=728x90;pos=top;dcove=d;tile=1;dcopt=ist;lan=en;c_type=splash;chn=homepage;cms=106a6c241b8797f52e1e77317b96a201;ord=1297708668?" type="text/javascript"></script>';

$("#ads-780x90-leaderboard").writeCapture().html(sampleCode);

Thanks a lot!

StatCounter tracking tag failing in IE 6, 7 and 8.

There is no Javascript error but a message (generated by the tag) that says: "Code corrupted. Insert fresh copy."

Here's the code:

$.writeCapture.proxyGetElementById = true;

$("#placeHolder1").writeCapture(
    "html", 
    "<!-- Start of StatCounter Code --><script type=\"text/javascript\">\n" +
    "var sc_project=5545436; \n" +
    "var sc_invisible=1; \n" +
    "var sc_security=\"823496b7\"; \n" +
    "</script><script type=\"text/javascript\" src=\"http://www.statcounter.com/counter/counter.js\"></script><!-- End of StatCounter Code -->\n" );

[enhancement] Add missing bower.json.

Hey, maintainer(s) of iamnoah/writeCapture!

We at VersionEye are working hard to keep up the quality of the bower's registry.

We just finished our initial analysis of the quality of the Bower.io registry:

7530 - registered packages, 224 of them doesnt exists anymore;

We analysed 7306 existing packages and 1070 of them don't have bower.json on the master branch ( that's where a Bower client pulls a data ).

Sadly, your library iamnoah/writeCapture is one of them.

Can you spare 15 minutes to help us to make Bower better?

Just add a new file bower.json and change attributes.

{
  "name": "iamnoah/writeCapture",
  "version": "1.0.0",
  "main": "path/to/main.css",
  "description": "please add it",
  "license": "Eclipse",
  "ignore": [
    ".jshintrc",
    "**/*.txt"
  ],
  "dependencies": {
    "<dependency_name>": "<semantic_version>",
    "<dependency_name>": "<Local_folder>",
    "<dependency_name>": "<package>"
  },
  "devDependencies": {
    "<test-framework-name>": "<version>"
  }
}

Read more about bower.json on the official spefication and nodejs semver library has great examples of proper versioning.

NB! Please validate your bower.json with jsonlint before commiting your updates.

Thank you!

Timo,
twitter: @versioneye
email: [email protected]
VersionEye - no more legacy software!

Problem with IE 6 and 7

The code below works on all major browsers and IE 8, but does not work on IE 6 and 7:

    writeCapture.proxyGetElementById = true;
    $("#placeHolder1").html( writeCapture.sanitize(
        "<script type=\"text/javascript\">\n" +
        "document.write(unescape(\'%3Cscript type=\"text/javascript\" src=\"\'+\n" +
        "document.location.protocol+\'//counter.goingup.com/js/tracker.js?st=xdxc7cr&b=5\"%3E%3C/script%3E\'));\n" +
        "</script>\n" ) );

The third party Javascript is a GoingUP tag. It creates an A element with id gubadge. On IE 6 and 7, this A element fails to be created.

Adsense workaround?

Hi Noah,
First of all, I want to congratulate you for developing such a useful tool. Now, let's go for the question :)

I'm working on a website that is displaying Adsense ads by means of ajax and, of course, I'm using writeCapture to display them. However, I stumbled with the following issue. I can only get 4 ads properly; when I try to get the 5th I get a 400 Bad Request status code.

If I then navigate not using ajax then the counter gets reset. It seems this is a restriction from Adsense and it is pretty annoying. Ideally, I would keep refreshing the ads when the user navigates the site. But as my knowledge of JQuery, JavaScript and even networking is very limited I find it quite difficult to get these stuff solved.

I have some questions in mind which I don't know the answer which seem to be key to solve this issue such as:
1- How does the server recognizes that there is a difference between the ajax requests and the non-ajax request? A status code?

2- Once I perform a non-ajax request and the count is reset, what difference has the following ajax request from the original 4?

3- Based on the previous questions, is there any way to fake a similar behaviour using writeCapture?

Ok, I know these are quite simple (stupid) questions and maybe not very related to writeCapture, but I would appreciate if you could give me a hand with this :)

Thanks in advance,
Mosty

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.