I have have one HTML canvas where I can do signature, For saving the canvas content I have used the plugin from the following URL,
https://github.com/devgeeks/Canvas2ImagePlugin
After using this plugin, I have one issue i.e, The image is saving to phone's gallery but the image is blank image that is just a black screen. Th canvas content is not saving. How can we get the canvas content and save it in the phone's gallery?
Script:
var sigCapture;
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady()
{
$(document).ready(function() {
sigCapture = new SignatureCapture( "signature" );
});
}
function saveCanvas()
{
window.canvas2ImagePlugin.saveImageDataToLibrary(
function(msg){
console.log(msg);
},
function(err){
console.log(err);
},
document.getElementById('signature')
);
}
</script>
HTML:
<div data-role="page" id="personalinfo">
<div data-role="header" id="header" data-position="fixed">
<h4>SBI Account Open</h4>
</div>
<h2>SIGNATURE</h2>
<div id="canvasContainer" >
<canvas id="signature" />
</div>
<button onClick='saveCanvas()'>Start</button>
</div>
Can anyone help me how to save the canvas content i.e, signature
I'm flying blind here, since don't have how to test it right now, but: canvas its not a self closing tag. Try changint it to <canvas id="signature"></canvas>
Related
I want to remove the dependency of Iframe from my application. What are the possible way I can call a different application URL other than using iframe, object or html embeded variable.
I am trying something like this.
<body>
<a class="ajax" href="http://www.google.com">
Open in Modal Window
</a>
<script type="text/javascript">
$(function (){
$('a.ajax').click(function() {
var url = this.href;
var dialog = $('<div style="display:none" class="Waiting"></div>').appendTo('body');
dialog.dialog({
close: function(event, ui) {
dialog.remove();
},
modal: true
});
dialog.load(
url,
{},
function (responseText, textStatus, XMLHttpRequest) {
dialog.removeClass('Waiting');
}
);
return false;
});
});
</script>
</body>
sorry can't comment
assuming there's no no anti CSF or similar measures on the target website you can use JavaScript ajax
or do it server side by grabbing the site
for better help describe what you're trying to archive what you did providing sample code if possible
I am creating a student ID card and then I am creating a button below it to give an option to the user to download the ID card as PDF.
My ID card div is as follows:
<!doctype html>
<html>
<head>
<title>Admin Registration</title>
<script src="js/jquery.min.js"></script>
<script src="js/show_message.js"></script>
<script type="text/javascript" src="js/jspdf.min.js"></script>
<script type=\"text/javascript\">
$(document).ready(function() {
var doc = new jsPDF();
var specialElementHandlers = {
'#editor': function (element, renderer) {
return true;
}
};
$('#cmd').click(function () {
doc.fromHTML($('receipt-outer').html(), 15, 15, {
'width': 170,\n" +
'elementHandlers': specialElementHandlers
});
doc.save('sample-file.pdf');
});
});
</script>
</head>
<body>
<div class='receipt-outer'>
<div class="receipt-inner">
<div class='idcard_heading'><p>Student ID Card</p></div>
<div class='clear'></div>
<div class='receipt_details'>
<div class='idcard_heading1'>
<div class='id_pic'>
<div class='id_pic_inner'>
<img src='images/pic"+fno+".jpg' height='120px' width='140px'><br>
<img src='images/sign"+fno+".jpg' height='50px' width='140px'>
</div>
<table id='id_table'>"+
<tr><th>Name : </th><td>"+s_fname+" "+s_mname+" "+s_sname+"</td></tr>
<tr><th>Course Name : </th><td>"+cname+"</td></tr>
<tr><th>Course code : </th><td>"+ccode+"</td></tr>
<tr><th>Commence of course : </th><td>"+st_from+"</td></tr>
<tr><th>End of course : </th><td>"+till+"</td></tr>
<tr><th>Timing : </th><td>"+ctiming+"</td></tr>
</table>
</div><br>
<div style='height:30px; margin-top:20px; margin-right:20px;'>
<span style='float:right;'>Issuing Authority</span></div>
<div id='editor'></div>
</div>
</div>
</div><br><br>
<button id='cmd'>Download </button>
</div>
</body>
</html>
I want to download the part of the div starting from the div class="receipt-outer" to the end in pdf format, just excluding the download button.
So I imported jspdf.min.js file and created a script which listens to the click event and then downloads the div as pdf. But I am getting the above mentioned error in the console whenever I hit the download button.
Please tell me where have I gone wrong. Why is it not downloading my file as pdf
dompdf might be what you are looking for:
Available here:
https://github.com/dompdf/dompdf
I am using the MapBox JavaScript API and trying to display some maps on a tab widget. Everything is working fine, except for the fact that when the page first loads, the maps do not load. As soon as I interact with the map in some way like zoom in/out or drag, this causes all of the map tiles to load.
<div class="g12" id="mapbox" style="display:none">
<div class="widget" id="widget_tabs" style="min-height:400px;">
<h3 class="handle">http://www.mapbox.com/mapbox.js/example/v1.0.0/</h3>
<div class="tab">
<ul>
<li>MapBox 1</li>
<li>MapBox 2</li>
<li>MapBox 3</li>
</ul>
<script src='http://api.tiles.mapbox.com/mapbox.js/v0.6.7/mapbox.js'></script>
<link href='http://api.tiles.mapbox.com/mapbox.js/v0.6.7/mapbox.css' rel='stylesheet' />
<style>
#map1 #map2 #map3 { position:absolute; }
#content {position: relative;}
</style>
<script>
$(document).ready(function() {
mapbox.auto('map1', 'examples.map-zr0njcqy');
mapbox.auto('map2', 'examples.map-zr0njcqy');
mapbox.auto('map3', 'examples.map-zr0njcqy');
$('#content').css({ height: 700});
var x = $('#mapbox'); /* cache the selector */
$('#map1,#map2,#map3').css({ width: x.width() * .98 });
$('#map1,#map2,#map3').css({ height: x.height() * .75});
});
</script>
<div id="map-1">
<div id='map1'></div>
</div>
<div id="map-2">
<div id='map2'></div>
</div>
<div id="map-3">
<div id='map3'></div>
</div>
</div> <!--end of class=tab-->
</div> <!--end of widget_tabs-->
How can I modify this code so that the it forces the maps to load correctly after the page loads? Thanks.
OpenLayers and MapBox OpenLayers.org is an open source JavaScript web mapping library distinguished from other alternatives, like Leaflet or Google Maps APIs, because of its huge set of components.
I spent the weekend creating sample apps by integrating OpenLayers with API's such as MapBox, WebGL etc... After all was said and done, I was extremely impressed with OpenLayers - and I plan to make use of OpenLayers in an upcoming POC/Project.
Here is a link to my test harness. From there you can also download the code for all of the examples, too.and finally...AN ANSWER TO YOUR QUESTION :) Defining an initialization JavaScript function: In my code below, I have defined a JavaScript function called initMap and invoke it by the browser to initialize the map after the page has finished loading.
<script>
function initMap() {
}
</script>
//Modify the body opening tag and add an onload event attribute to it:
<body onload="initMap();"> </body>
// Start - the actual code. See the test harness for working example
OpenLayers.ProxyHost = "/cgi-bin/proxy.cgi?url=";
function initMap(){
var map = new OpenLayers.Map("map");
var earth = new OpenLayers.Layer.XYZ(
"Natural Earth",
["http://a.tiles.mapbox.com/v3/
mapbox.natural-earth-hypso-bathy/${z}/${x}/${y}.png",
"http://b.tiles.mapbox.com/v3/
mapbox.natural-earth-hypso-bathy/${z}/${x}/${y}.png",
"http://c.tiles.mapbox.com/v3/
mapbox.natural-earth-hypso-bathy/${z}/${x}/${y}.png",
"http://d.tiles.mapbox.com/v3/
mapbox.natural-earth-hypso-bathy/${z}/${x}/${y}.png"
],
{
attribution: "Tiles © <a href='http://mapbox.com/'>MapBox</a>",
sphericalMercator: true,
wrapDateLine: true,
numZoomLevels: 19
}
);
map.addLayer(earth);
map.setCenter(new OpenLayers.LonLat(105, 35).transform(
new OpenLayers.Projection("EPSG:4326"),
new OpenLayers.Projection("EPSG:900913")), 4);
}
I have got my video & its playing fine, but now i need to add a logo on my video tag at right bottom corner(the coordinates(2,2,60,60) icon size is 60*60),
I thought of using canvas, but came up some thing like this..
<html>
<head>
<title>testpage</title>
<script type="text/javascript">
window.addEventListener('load', function () {
var element = document.getElementById('myCanvas');
if (!element || !element.getContext) {
return;
}
var context = element.getContext('2d');
if (!context || !context.drawImage) {
return;
}
var google_img = new Image();
google_img.addEventListener('load', function () {
context.drawImage(this, 2, 2, 60, 60);
},false);
google_img.src = "logo.png";
},false);
</script>
</head>
<body>
<div align="center" style="padding-top:25px;">
<video src="Simplevideo.mp4" width="610" height="380" type="video/mp4" controls="controls"><p>Your browser does not support the video.</p></video>
<canvas id="myCanvas" width="62" height="62">Your browser does not support HTML5 Canvas element.</canvas>
</div>
</body>
</html>
any help to get it..
thanks in advance
shameer ali shaik
You could simply use a div as loxxy said in a comment, but if you really want to use canvas for some reason here is a jsfiddle with your code (fixed) :
http://jsfiddle.net/aS9VG/
The trick is to set the element to an absolute position so it can overlap another element :
style="position:absolute;right:150px;bottom:300px"
I want to know how to load an image into the HTML5 canvas. Specifically, I want a script that swaps one image for another on the canvas during mouse over with the original image fading out. I am new to HTML5 and have this code:
<canvas id="myCanvas" width="500" height="500" />
<script type="text/javascript">
function drawbackground() {
char.fillStyle="blue";
cxt.fillRect(0,0,500,500);
}
var charx=0;
var chary=0;
var c=document.getElementById("myCanvas");
var cxt=c.getContext("2d");
var char=c.getContext("2d");
drawbackground();
char.fillStyle="black";
var imgObj = new Image();
imgObj.src='map1.png';
imgObj.onload = function () {
// Draw the image on the canvas
char.drawImage(imgObj, 10, 10);
}
</script>
Is this in the right direction?
You can do this without the HTML5 Canvas. To swap an image on mouse over it is easiest to use a JavaScript Framework called jQuery, get it for free here: http://jquery.com/.
With jQuery all you need to do is something like the following:
First, create an image Tag.
<img src="image1.png" id="myimage" />
Next add JavaScript to handle the mouse over event. You can learn more about jQuery events here: http://api.jquery.com/category/events/
$("#myimage").mouseover(function() {
$(this).src = this.src.replace("image2.png");
});
The example above will change the image on mouse over. To do the fade effects, you need to do a little more: You can learn more about jQuery effects here: http://api.jquery.com/category/effects/
I would create two images for the effect and position each over the other with the css property set to hide image 2.
<div id="imageHolder">
<img src="image1.png" id="myimage1" />
<img src="image2.png" id="myimage2" style="display:none" />
</div>
Next comes the JavaScript:
$("#imageHolder").mouseover(function() {
$("#image1").fadeOut();
$("#image2").show();
});
$("#imageHolder").mouseout(function() {
$("#image1").fadeIn();
$("#image2").hide();
});
There are many ways to accomplish this and the code above is not tested, but should provide you with a basis to quickly create the desired effect.