tags:

views:

42

answers:

2

Hi,

I attempted to load a simple HTML file into a canvas (browser = ff 3.66).

var canvas= document.getElementById('oneElement');
var ctx= canvas.getContext('2d');

var img= new Image();
ctx.drawImage(img, 0, 0, img.width, img.height);
img.src = 'data:text/html,<table><tr><td>data 1<td>data 2</td></tr>
<tr><td>data 3><td>data 4</td></tr>
<tr><td>data 5><td>data 6</td></tr>
</table>
'; 

How? Thanks.

+1  A: 

It seems you have newlines inside your Javascript string -- which is not allowed.

You should remove those newlines, putting the string in only one line :

img.src = 'data:text/html,<table><tr><td>data1<td>data2</td></tr><tr><td>data 3><td>data 4</td></tr><tr><td>data 5><td>data 6</td></tr></table>'; 

Or, if you want to keep your code readable, a solution could be to use several small strings, and to use strings-concatenation :

img.src = 'data:text/html,<table><tr><td>data 1<td>data 2</td></tr>' +
'<tr><td>data 3><td>data 4</td></tr>' +
'<tr><td>data 5><td>data 6</td></tr>' +
'</table>'; 
Pascal MARTIN
Pascal, thank you. with the strings-concatenation technique, I've made the syntax correct. However, the function failed, that is, neither var tm = document.createElement('img');tm.src = 'data:text/html,{html code here};nor using a canvas with drawImage method then mapits src to the above similar HTML data callwould work with FF 3.66I'm stuck. What now?Don
Don Don
A: 

Adding a '\' character at the end of each line before the line with the closing single quote should work.

img.src = 'here \
is an \
example';
patros