此腳本可讓您將 html2canvas.js 與不同的伺服器、連接埠和協定(http、https)一起使用,從而防止在匯出映像的<canvas>
時發生「污染」。
您不使用 ASP Classic,但需要 html2canvas 與代理程式一起使用,請參閱其他代理程式:
當在<canvas>
中新增屬於另一個網域的影像,然後嘗試匯出新影像的畫布時,會發生安全性錯誤(實際上發生的是安全鎖),這可能會傳回錯誤:
安全錯誤:DOM 異常 18
錯誤:試圖突破用戶代理的安全策略。
我要求您關注我或“星標”我的存儲庫以跟踪更新
<!DOCTYPE html >
< html >
< head >
< meta charset =" utf-8 " >
< title > html2canvas asp (vbscript) proxy </ title >
< script src =" html2canvas.js " > </ script >
< script >
//<![CDATA[
( function ( ) {
window . onload = function ( ) {
html2canvas ( document . body , {
"logging" : true , //Enable log (use Web Console for get Errors and Warings)
"proxy" : "html2canvasproxy.asp" ,
"onrendered" : function ( canvas ) {
var img = new Image ( ) ;
img . onload = function ( ) {
document . body . appendChild ( img ) ;
} ;
img . error = function ( ) {
if ( window . console . log ) {
window . console . log ( "Not loaded image from canvas.toDataURL" ) ;
} else {
alert ( "Not loaded image from canvas.toDataURL" ) ;
}
} ;
img . src = canvas . toDataURL ( "image/png" ) ;
}
} ) ;
} ;
} ) ( ) ;
//]]>
</ script >
</ head >
< body >
< p >
< 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 " >
</ p >
< p >
< img alt =" facebook image redirect " src =" https://graph.facebook.com/1415773021975267/picture " >
</ p >
</ body >
</ html >
如果您對腳本有任何問題,建議使用瀏覽器中的 Web 控制台分析日誌:
取得網路結果:
另一種方法是直接訪問連結來診斷問題:
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
將[DOMAIN]
替換為您的網域(例如 127.0.0.1),並將[PATH]
替換為您的專案資料夾(例如 project-1/test),如下所示:
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