Javascript Articles - Page 426 of 534

Example of createSignalingChannel() in HTML5

Vrundesha Joshi
Updated on 29-Jan-2020 10:12:57

177 Views

Web RTC required peer-to-peer communication between browsers. This mechanism required signalling, network information, session control and media information. Web developers can choose different mechanism to communicate between the browsers such as SIP or XMPP or any two way communications. An example of createSignalingChannel():var signalingChannel = createSignalingChannel(); var pc; var configuration = ...; // run start(true) to initiate a call function start(isCaller) {    pc = new RTCPeerConnection(configuration);    // send any ice candidates to the other peer    pc.onicecandidate = function (evt) {       signalingChannel.send(JSON.stringify({ "candidate": evt.candidate }));    };        // once remote stream ... Read More

HTML5 IndexedDB Example

Sravani S
Updated on 29-Jan-2020 10:13:33

261 Views

The following function is an example of IndexedDB to add data:function add() {    var request = db.transaction(["employee"], "readwrite")    .objectStore("employee")    .add({ id: "001", name: "Amit", age: 28, email: "demo1@example.com" });    request.onsuccess = function(event) {       alert("Amit has been added to your database.");    };    request.onerror = function(event) {       alert("Unable to add data\rAmit is already exist in your database! ");    } }Above, we added the following details in the database:const employeeData = [    { id: "001", name: "Amit", age: 28, email: "demo1@example.com" }, ];

How to detect a particular feature through JavaScript with HTML

Nishtha Thakur
Updated on 29-Jan-2020 08:37:27

211 Views

Use Modernizr in HTML to detect a feature like audio through JavaScript:if (Modernizr.audio) {    /* properties for browsers that    support audio */ } else{    /* properties for browsers that    does not support audio */ }

How to check web browser support in HTML5

Smita Kapse
Updated on 29-Jan-2020 08:35:39

292 Views

You can try to run the following code to detect a web worker feature available in a web browser:           Big for loop                      function myFunction(){             if (Modernizr.webworkers) {                alert("Congratulations!! You have web workers support." );             } else{                alert("Sorry!! You do not have web workers support." );             }          }                     Click me     The following is the result:

Log error to console with Web Workers in HTML5

karthikeya Boyini
Updated on 29-Jan-2020 08:34:25

707 Views

Here is an example of an error handling function in a Web Worker JavaScript file that logs errors to the console.ExampleWith error handling code, above example would become like the following:           Big for loop                var worker = new Worker('bigLoop.js');          worker.onmessage = function (event) {             alert("Completed " + event.data + "iterations" );          };          worker.onerror = function (event) {             console.log(event.message, event);          };          function sayHello(){             alert("Hello sir...." );          }                        

Why HTML5 Web Workers are useful?

Anvi Jain
Updated on 29-Jan-2020 08:33:46

216 Views

JavaScript was designed to run in a single-threaded environment, meaning multiple scripts cannot run at the same time. Consider a situation where you need to handle UI events, query and process large amounts of API data, and manipulate the DOM.JavaScript will hang your browser in situation where CPU utilization is high. Let us take a simple example where Javascript goes through a big loop:           Big for loop                function bigLoop(){             for (var i = 0; i

Difference between dragenter and dragover event in HTML5

Samual Sam
Updated on 30-Jul-2019 22:30:22

492 Views

dragenterThe dragenter event is used to determine whether the drop target is to accept the drop. If the drop is to be accepted, then this event has to be canceled.dragoverThe dragover event, which is used to determine what feedback is to be shown to the user. If the event is canceled, then the feedback (typically the cursor) is updated based on the dropEffect attribute's value.

Resize image before submitting the form HTML5

karthikeya Boyini
Updated on 29-Jan-2020 08:22:08

350 Views

To resize the image before submitting the form, you need to use the drawImage() method.Scale the original image and draws the scaled version on the canvas at [0,0]context.drawImage( img, 0,0,img.width,img.height, 0,0,myWidth,UseHeight );Above, we saw the following:Here,var myWidth = Math.floor( img.width * Scale ); var myHeight = Math.floor( img.height * Scale );And,var x = Math.floor( ( world.width - myWidth) / 2 ); var y = Math.floor( ( world.height - myHeight) / 2 );

What are the DataTransfer object attributes?

Nitya Raut
Updated on 29-Jan-2020 08:21:27

568 Views

The DataTransfer object holds data about the drag and drop operation. This data can be retrieved and set in terms of various attributes associated with the DataTransfer object.The following are the attributes:Sr.No.DataTransfer attributes and their description1dataTransfer.dropEffect [ = value ]Returns the kind of operation that is currently selected.This attribute can be set, to change the selected operation.The possible values are none, copy, link, and move.2dataTransfer.effectAllowed [ = value ]Returns the kinds of operations that are to be allowed.This attribute can be set, to change the allowed operations.The possible values are none, copy, copyLink, copyMove, link, linkMove, move, all and uninitialized.3dataTransfer.typesReturns a DOMStringList ... Read More

Drop target listens to which events in HTML5?

Lakshmi Srinivas
Updated on 29-Jan-2020 08:20:54

154 Views

To accept a drop, the drop target has to listen to at least three events. The dragenter event, which is used to determine whether the drop target is to accept the drop. If the drop is to be accepted, then this event has to be canceled. The dragover event, which is used to determine what feedback is to be shown to the user. If the event is canceled, then the feedback (typically the cursor) is updated based on the dropEffect attribute's value. Finally, the drop event, which allows the actual drop to be performed.

Advertisements