jrough
5/12/2016 1:11:00 AM
On Tuesday, May 10, 2016 at 1:03:13 AM UTC-7, John Harris wrote:
> On Tue, 10 May 2016 05:42:14 +0200, Thomas 'PointedEars' Lahn
> <PointedEars@web.de> wrote:
>
> >JRough wrote:
> >^^^^^^
> >Your *real* name belongs in your “From”.
> <snip>
>
> Now explain why
> From: JRough <janis.rough@gmail.com>
> isn't suitable according to your rules.
>
> John
I made the suggested fixes and I am still getting the error undefined:
Navigated to http://localhost/html5test/page.html
sample.js:11 GET http://localhost/html5test/undefined 404 (Not Found)getImage1Data @ sample.js:11element.onclick @ sample.js:61
sample.js:44 Uncaught TypeError: canvas.toDataURI is not a function
Is there any more suggestions?
"use strict";
var image2Src = null;
function getImage1Data(){
var image1Src ;
var xhttp = new XMLHttpRequest();
xhttp.open("Get", toDataURI('/html5test/myFirstImage.png',function(base64Img){}) , true);
xhttp.send(null);
image1Src = xhttp.responseText; //Assume src = 'myFirstImg.png', 200x200 px//
}
function getImage2Data(){
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function(){
if(xhttp.readyState == 4 && xhttp.status == 200)
getSrc(xhttp.responseText);
};
xhttp.open("Get",toDataURI('/html5test/myLastImage.png',function(base64Img){}), true);
xhttp.send(null);
}
function getSrc(text){
image2Src = text; //Assume src = 'myLastImg.png', 10x10 px
}
function toDataURI(url, callback, outputFormat){
var img = new Image();
img.crossOrigin = 'Anonymous';
img.onload = function(){
var canvas = document.createElement('CANVAS');
var ctx = canvas.getContext('2d');
var dataURL;
canvas.height = this.height;
canvas.width = this.width;
ctx.drawImage(this, 0, 0);
dataURL = canvas.toDataURI(outputFormat);
callback(dataURL);
canvas = null;
};
img.src = url;
}
function add(type) {
//Create an input type dynamically.
var element = document.createElement(type);
//Assign different attributes to the element.
element.type = type;
element.value = type; // Really? You want the default value to be the type string?
element.name = type; // And the name too?
element.onclick = function(event) { // Note this is a function
var buttons = document.getElementsByTagName('button');
if (event.target == buttons[0] ){
getImage1Data();
}
if (event.target== buttons[1] ) {
getImage2Data();
}
};
var foo = document.getElementById("btnDiv");
//Append the element in page (in span).
foo.appendChild(element);
}