你需要給圖像的完整路徑,以創建使用htm2canvas的div的圖像
FOR I.E.
<img src="https://avatars0.githubusercontent.com/u/10482079?s=140" class="img">
我已經爲我測試了這個和它的工作。 它在Chrome工作太...運行的代碼片段中鉻
$(window).load(function(){
$('#load').click(function(){
html2canvas($('#testdiv'), {
onrendered: function (canvas) {
var img = canvas.toDataURL("image/png")
window.open(img);
}
});
});
});
div#testdiv
{
height:500px;
width:500px;
position: relative;
}
.fuente{
\t font-family: 'Chewy', cursive;
\t margin-left: 50px;
\t margin-bottom: 50px;
}
h1{
\t color: #EE1F3B;
text-shadow: 1px 1px 2px black;
font-size: 70px;
}
.img{
\t width: 100px;
\t height: 100px;
}
.imgequipo{
position: absolute;
top: 90px;
left: 335px;
width: 100px;
\t height: 100px;
}
h2{
position: absolute;
top: 110px;
font-family: 'Oswald', sans-serif;
color: #ffe400;
font-size:80px;
font-weight: bold;
left: 30px;
}
body{
\t margin-top: 100px;
\t margin-bottom: 100px;
\t background-color: #eeeeee;
}
<html>
<head>
<script src="http://html2canvas.hertzen.com/build/html2canvas.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link href='http://fonts.googleapis.com/css?family=Chewy' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Oswald' rel='stylesheet' type='text/css'>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class ="container">
<h1 class="fuente text-center">prueba</h1>
<div class="col-md-1 col-md-offset-3">
<div id="testdiv">
<img src="https://avatars0.githubusercontent.com/u/10482079?s=140" class="img">
<img src="https://avatars0.githubusercontent.com/u/10482079?s=140" class="imgequipo">
<h2>prueba2</h2>
</div><br>
<button id="load" class="btn btn-info">Generar Imagen</button>
</div>
</div>
</body>
</html>
不看它聽起來像你犧牲品同源策略的代碼。 Afaik無法以這種方式在畫布中包含來自其他域的圖像。 – Sirko
我能做什麼? :( –