Found 8894 Articles for Front End Technology

How do I add a simple onClick event handler to an HTML5 canvas element?

Ankith Reddy
Updated on 04-Mar-2020 04:46:50

4K+ Views

The elements that are drawn in canvas element have no representation. Their only representation is the pixels they use and their color. Drawing to a canvas element means drawing a bitmap in immediate mode. To get a click event on a canvas element (shape), you need to capture click events on the canvas HTML element and determine which element was clicked. This requires storing the element’s width and height.To add a click event to your canvas element, use the below-given codecanvas.addEventListener('click', function() { }, false);ExampleTo determine what element was clicked, use the following code snippet −var e = document.getElementById('myCanvas'),   ... Read More

HTML5 check if audio is playing

mkotla
Updated on 04-Mar-2020 04:59:44

4K+ Views

Use the following to check if audio is playing −functionisPlaying(audelem) {    return!audelem.paused; }The above code can be used to check ifaudio is playing or not. The audio tag has a paused property.The paused property returns whether the audio/video is paused.You can also toggle −functiontogglePause() {    if(newAudio.paused && newAudio.currentTime > 0 && !newAudio.ended) {       newAudio.play();    } else {       newAudio.pause();    } }

Using HTML5 file uploads with AJAX and jQuery

Arjun Thakur
Updated on 04-Mar-2020 04:58:53

464 Views

When the form is submitted, catch the submission process and try to run the following code snippet for file upload −// File 1 var myFile = document.getElementById('fileBox').files[0]; var reader = new FileReader(); reader.readAsText(file, 'UTF-8'); reader.onload = myFunc; function myFunc(event) {    var res = event.target.result; var fileName = document.getElementById('fileBox').files[0].name;    $.post('/myscript.php', { data: res, name: fileName }, continueSubmission); }Then, on the server side (i.e. myscript.php) −$data = $_POST['data']; $fileName = $_POST['name']; $myServerFile = time().$fileName; // Prevent overwriting $fp = fopen('/uploads/'.$myServerFile, 'w'); fwrite($fp, $data); fclose($fp); $retData = array( "myServerFile" => $myServerFile ); echo json_encode($retData);Read More

HTML 5 local Storage size limit for sub domains

Sreemaha
Updated on 04-Mar-2020 04:57:24

421 Views

HTML5's localStorage databases are size-limited. The standard sizes are 5 or 10 MB per domain. A limit of 5 MB per origin is recommended.The following is stated −User agents should guard against sites storing data under their origin's other affiliated sites, e.g. storing up to the limit in a1.example.com,a2.example.com, a3.example.com, etc, circumventing the mainexample.com storage limit.For size limit −A mostly arbitrary limit of five megabytes per origin is suggested. Implementation feedback is welcome and will be used to update this suggestion in the future.

How can I use the HTML5 canvas element in IE?

Chandu yadav
Updated on 04-Mar-2020 04:53:16

167 Views

Use excanvas JavaScript library to use HTML5 canvas in Internet Explorer(IE).The excanvas library is an add-on, which will add the HTML5 canvas functionality to the old IE browsers (IE7-8).Firefox, Safari and Opera 9 support the canvas tag to allow 2D command-based drawing operations.ExplorerCanvas brings the same functionality to Internet Explorer. To use the HTML5 canvas element in IE, include the ExplorerCanvas tag in the same directory as your HTML files, and add the following code to your page in the head tag.

How to fix getImageData() error ‘The canvas has been tainted by cross-origin data’ in HTML?

George John
Updated on 04-Mar-2020 04:52:20

2K+ Views

The crossOrigin attribute allows images that are loaded from external origins to be used in canvas like the one they were being loaded from the current origin.Using images without CORS approval tains the canvas. Once a canvas has been tainted, you can no longer pull data back out of the canvas. By loading the canvas from cross origin domain, you are tainting the canvas.You can prevent this by setting −img.crossOrigin = "Anonymous";This works if the remote server sets the header aptly −Access-Control-Allow-Origin "*"

How to programmatically empty browser cache with HTML?

usharani
Updated on 01-Jun-2020 10:53:08

2K+ Views

You can tell your browser not to cache your page by using the following meta tags − In addition, try the following:  Append a parameter/string to the filename in the script tag. Change it when the file changes.Then the next time you update the file, just update the version i.e.

Is it possible to style HTML5 audio tag?

varma
Updated on 04-Mar-2020 04:50:27

4K+ Views

HTML 5 audio tags can be styled. By using the audio tag with “controls” attribute, the default browsers player is used. You can customize by not using the browsers controls. By removing the controls attribute, you can hide the built in browser user’s interface −    Play    Pause    Vol+    Vol- You can also add CSS classes to each one of the elements and style them accordingly.

Checking if a key exists in HTML5 Local Storage

Sreemaha
Updated on 24-Jun-2020 12:30:42

1K+ Views

The getitem(key) takes value for one parameter and returns the value associated with the key. The given key is present in the list associated with the object.if(localStorage.getItem("user")===null) {    //... }But if the key is not present in the list then it passes null value by using the below-given codeYou can also follow the below-given procedure −if("user" in localStorage){    alert('yes'); } else {    alert('no'); }

Drawing text to HTML5 with @fontface does not work at the first time

Chandu yadav
Updated on 01-Jun-2020 10:58:45

373 Views

 Drawing text in a canvas with a typeface that is loaded via @font-face does not show text correctly at first. This is because the browser has not yet loaded the font from network. Therefore, it makes use of the font, which is already available.The font has to be completed loaded before it is used. This can be ensured using tag. If you want to make sure that the font is available and have some other elements preloaded, then you can do this by using the tag as under  You can also load font like this −var newFont = ... Read More

Advertisements