项目作者: brcontainer

项目描述 :
Vbscript (asp classic) Proxy html2canvas
高级语言: Classic ASP
项目地址: git://github.com/brcontainer/html2canvas-asp-vbscript-proxy.git
创建时间: 2013-08-12T02:10:48Z
项目社区:https://github.com/brcontainer/html2canvas-asp-vbscript-proxy

开源协议:MIT License

下载


html2canvas-asp-vbscript-proxy 0.0.4

Vbscript (asp classic) Proxy html2canvas

This script allows you to use html2canvas.js with different servers, ports and protocols (http, https),
preventing to occur “tainted” when exporting the <canvas> for image.

Others scripting language

You do not use ASP Classic, but need html2canvas working with proxy, see other proxies:

Problem and Solution

When adding an image that belongs to another domain in <canvas> and after that try to export the canvas
for a new image, a security error occurs (actually occurs is a security lock), which can return the error:

SecurityError: DOM Exception 18

Error: An attempt was made to break through the security policy of the user agent.

Follow

I ask you to follow me or “star” my repository to track updates

Usage

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>html2canvas asp (vbscript) proxy</title>
  6. <script src="html2canvas.js"></script>
  7. <script>
  8. //<![CDATA[
  9. (function() {
  10. window.onload = function(){
  11. html2canvas(document.body, {
  12. "logging": true, //Enable log (use Web Console for get Errors and Warings)
  13. "proxy":"html2canvasproxy.asp",
  14. "onrendered": function(canvas) {
  15. var img = new Image();
  16. img.onload = function() {
  17. document.body.appendChild(img);
  18. };
  19. img.error = function() {
  20. if(window.console.log) {
  21. window.console.log("Not loaded image from canvas.toDataURL");
  22. } else {
  23. alert("Not loaded image from canvas.toDataURL");
  24. }
  25. };
  26. img.src = canvas.toDataURL("image/png");
  27. }
  28. });
  29. };
  30. })();
  31. //]]>
  32. </script>
  33. </head>
  34. <body>
  35. <p>
  36. <img alt="google maps static" src="http://maps.googleapis.com/maps/api/staticmap?center=40.714728,-73.998672&zoom=12&size=800x600&maptype=roadmap&sensor=false">
  37. </p>
  38. <p>
  39. <img alt="facebook image redirect" src="https://graph.facebook.com/1415773021975267/picture">
  40. </p>
  41. </body>
  42. </html>

Using Web Console

If you have any problems with the script recommend to analyze the log using the Web Console from your browser:

Get NetWork results:

An alternative is to diagnose problems accessing the link directly:

http://[DOMAIN]/[PATH]/html2canvasproxy.php?url=http%3A%2F%2Fmaps.googleapis.com%2Fmaps%2Fapi%2Fstaticmap%3Fcenter%3D40.714728%2C-73.998672%26zoom%3D12%26size%3D800x600%26maptype%3Droadmap%26sensor%3Dfalse%261&callback=html2canvas_0

Replace [DOMAIN] by your domain (eg. 127.0.0.1) and replace [PATH] by your project folder (eg. project-1/test), something like:

http://localhost/project-1/test/html2canvasproxy.php?url=http%3A%2F%2Fmaps.googleapis.com%2Fmaps%2Fapi%2Fstaticmap%3Fcenter%3D40.714728%2C-73.998672%26zoom%3D12%26size%3D800x600%26maptype%3Droadmap%26sensor%3Dfalse%261&callback=html2canvas_0