Skip to content

Instantly share code, notes, and snippets.

@logankoester
Created June 14, 2012 03:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save logankoester/2927868 to your computer and use it in GitHub Desktop.
Save logankoester/2927868 to your computer and use it in GitHub Desktop.
Sandboxing 3rd-party ad code
<html>
<head>
<script type="text/javascript" src="//caja.appspot.com/caja.js"></script>
<script type="text/javascript">
caja.initialize({ cajaServer: 'https://caja.appspot.com/', debug: true });
// Force all network requests to use HTTPS.
// Prevents Insecure Content errors when the host page was loaded securely.
var uriPolicy = {
rewrite: function(uri) { return( uri.replace(/^http:/, 'https:') ); }
}
// Load the ad into a sandbox
caja.load(document.getElementById('ad_sandbox'), uriPolicy, function(frame) {
frame.code( 'https://ad.doubleclick.net/YOUR_AD_LOADER', 'text/javascript' ).run( function(f){
// Use callbacks to clean up further after ad code execution
});
});
</script>
</head>
<body>
<div id="ad_sandbox"></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment