I have a task when I need to upload a URL (eg www.yahoo.com)
on my web page and take a screenshot. I use html2canvas for a screenshot and adding it to the body of the page.
The page indicated by the URL successfully loads in the iframe inside the div element. But when I try to take a screenshot, the iframe area is empty.
Below is the code for previewURL
and screenshot
.
//to preview the URL content function previewUrl(url,target){ //use timeout coz mousehover fires several times clearTimeout(window.ht); window.ht = setTimeout(function(){ var div = document.getElementById(target); div.innerHTML = '<iframe style="width:100%;height:100%;" frameborder="0" src="' + url + '" />'; },20); } function pic() { html2canvas(document.body, { onrendered: function(canvas) { document.body.appendChild(canvas); } }); };
And the HTML part goes here:
<body> <input type="button" class="clear-button" onclick="pic();" value="Take Screenshot" > <a href="http://www.yahoo.com" onmouseover="previewUrl(this.href,'div1')">Hover to load</a> <div id="div1"></div> </body>
The screenshot looks something like this: ![enter image description here](https://fooobar.com//img/0c47c8f057114b686e516bb2026a2efc.png)
I am stuck and do not understand why this is happening. I want something similar to this one that can load a url and then onclick can give me a screenshot.
source share