|
| 1 | +<script src="/dist/html2canvas.js"></script> |
| 2 | +<script src="/dist/html2canvas.svg.js"></script> |
| 3 | +<script> |
| 4 | + var date = new Date(); |
| 5 | + var message, timeoutTimer, timer; |
| 6 | + |
| 7 | + function addRow(table,field,val){ |
| 8 | + var tr = $('<tr />').appendTo( $(table)); |
| 9 | + tr.append($('<td />').css('font-weight','bold').text(field)).append($('<td />').text(val)); |
| 10 | + |
| 11 | + } |
| 12 | + |
| 13 | + function iframeLoad(iframe) { |
| 14 | + var body = $(iframe).contents().find('body').get(0); |
| 15 | + |
| 16 | + html2canvas(body, { |
| 17 | + allowTaint: true, |
| 18 | + taintTest: false, |
| 19 | + logging: true |
| 20 | + }).then(function( canvas ) { |
| 21 | + $("#content").empty().append(canvas); |
| 22 | + $('#getscreenshot').prop('disabled', false); |
| 23 | + $('base').attr('href',""); |
| 24 | + }); |
| 25 | + } |
| 26 | + |
| 27 | + $(function(){ |
| 28 | + $('#recommended a').click(function(e){ |
| 29 | + e.preventDefault(); |
| 30 | + $('#url').val(this.href); |
| 31 | + $('button').click(); |
| 32 | + }) |
| 33 | + |
| 34 | + var iframe,d; |
| 35 | + |
| 36 | + $('#getscreenshot').click(function(e){ |
| 37 | + e.preventDefault(); |
| 38 | + $(this).prop('disabled',true); |
| 39 | + var url = $('#url').val(); |
| 40 | + $('#content').append($('<img />').attr('src','/site/img/loading.gif').css('margin-top',40)); |
| 41 | + |
| 42 | + var urlParts = document.createElement('a'); |
| 43 | + urlParts.href = url; |
| 44 | + |
| 45 | + $.ajax({ |
| 46 | + data: { |
| 47 | + xhr2:false, |
| 48 | + url:urlParts.href |
| 49 | + |
| 50 | + }, |
| 51 | + url: "http://html2canvas.appspot.com/query", |
| 52 | + dataType: "jsonp", |
| 53 | + success: function(html){ |
| 54 | + iframe = document.createElement('iframe'); |
| 55 | + $(iframe).css({ |
| 56 | + 'visibility':'hidden' |
| 57 | + }).width($(window).width()).height($(window).height()); |
| 58 | + $('#content').append(iframe); |
| 59 | + d = iframe.contentWindow.document; |
| 60 | + |
| 61 | + d.open(); |
| 62 | + |
| 63 | + $(iframe.contentWindow).load(iframeLoad.bind(null, iframe)); |
| 64 | + |
| 65 | + $('base').attr('href',urlParts.protocol+"//"+urlParts.hostname+"/" + urlParts.pathname); |
| 66 | + html = html.replace("<head>","<head><base href='"+urlParts.protocol+"//"+urlParts.hostname+"/" + urlParts.pathname + "' />"); |
| 67 | + if ($("#disablejs").prop('checked')){ |
| 68 | + html = html.replace(/\<script/gi,"<!--<script"); |
| 69 | + html = html.replace(/\<\/script\>/gi,"<\/script>-->"); |
| 70 | + } |
| 71 | + |
| 72 | + d.write(html); |
| 73 | + d.close(); |
| 74 | + } |
| 75 | + }); |
| 76 | + }); |
| 77 | + }); |
| 78 | +</script> |
| 79 | + |
| 80 | +<ul class="breadcrumb"> |
| 81 | + <li><a href="/">Home</a> <span class="divider">/</span></li> |
| 82 | + <li><a href="/examples.html">Examples</a> <span class="divider">/</span></li> |
| 83 | + <li class="active">Test console</li> |
| 84 | +</ul> |
| 85 | + |
| 86 | +<div class="page-header"> |
| 87 | + <h1>JavaScript webpage renderer</h1> |
| 88 | +</div> |
| 89 | + |
| 90 | +<p> |
| 91 | + The whole screenshot is created with JavaScript. The only server interaction that is happening on this page is the proxy for loading the external pages/images into JSONP/CORS enabled page and onwards onto the JavaScript renderer script. |
| 92 | + There are a lot of problemii s of loading external pages, even with a proxy, and as such many pages will not render at all. If you wish to try the script properly, I recommend you get a copy of the source from <a href="https://github.com/niklasvh/html2canvas">here</a> instead. |
| 93 | +</p> |
| 94 | +<form class="well form-search"> |
| 95 | + <label for="url">Website URL:</label> |
| 96 | + <input type="url" id="url" value="http://www.yahoo.com" class="input-medium search-query" /><button class="btn" id="getscreenshot">Get screenshot!</button> |
| 97 | +</form> |
| 98 | + |
| 99 | +<label for="disablejs">Disable JavaScript (recommended, doesn't work well with the proxy)</label> <input type="checkbox" id="disablejs" checked /><br /> |
| 100 | +<small>Tested with Google Chrome 12, Firefox 4 and Opera 11.5</small> |
| 101 | + |
| 102 | +<h3>Recommended (tested) pages:</h3> |
| 103 | + |
| 104 | +<ul id="recommended"> |
| 105 | + <li><a href="http://www.twitter.com/niklasvh">twitter.com</a></li> |
| 106 | + <li><a href="http://www.yahoo.com">yahoo.com</a></li> |
| 107 | + <li><a href="http://www.jquery.com">jquery.com</a></li> |
| 108 | + <li><a href="http://www.google.com">google.com</a></li> |
| 109 | + <li><a href="https://github.com/niklasvh/html2canvas">github.com</a></li> |
| 110 | + <li><a href="http://www.smashingmagazine.com">smashingmagazine.com</a></li> |
| 111 | + <li><a href="http://www.mashable.com">mashable.com</a></li> |
| 112 | + <li><a href="http://www.facebook.com/google">facebook.com/google</a></li> |
| 113 | + <li><a href="http://www.youtube.com/">youtube.com</a></li> |
| 114 | + <li><a href="http://www.cnn.com/">cnn.com</a></li> |
| 115 | + <li><a href="http://www.engadget.com/">engadget.com (lot of elements, very slow)</a></li> |
| 116 | + <li><a href="http://eu.battle.net/en/">battle.net</a></li> |
| 117 | +</ul> |
| 118 | + |
| 119 | +<div id="content"></div> |
0 commit comments