Javascript Articles

Page 517 of 534

How to disable browser's back button with JavaScript?

George John
George John
Updated on 24-Jan-2020 3K+ Views

To disable web browsers’ back button, try to run the following code. This is the code for current HTML page,Example           Disable Browser Back Button                               Next Page               $(document).ready(function() {          function disablePrev() { window.history.forward() }          window.onload = disablePrev();          window.onpageshow = function(evt) { if (evt.persisted) disableBack() }       });     The following is the code for newpage.html,           Go to back page using web browser back button.     a

Read More

How to create SVG graphics using JavaScript?

Govinda Sai
Govinda Sai
Updated on 24-Jan-2020 710 Views

All modern browsers support SVG and you can easily create it using JavaScript. Google Chrome and Firefox both support SVG.With JavaScript, create a blank SVG document object model (DOM). Using attributes, create a shape like a circle or a rectangle.var mySvg = "http://www.w3.org/2000/svg"; var myDoc = evt.target.ownerDocument; var myShape = svgDocument.createElementNS(mySvg, "circle"); myShape.setAttributeNS(null, "cx", 40); myShape.setAttributeNS(null, "cy", 40); myShape.setAttributeNS(null, "r", 30); myShape.setAttributeNS(null, "fill", "yellow");

Read More

How to set the top margin of an element with JavaScript?

Lakshmi Srinivas
Lakshmi Srinivas
Updated on 24-Jan-2020 2K+ Views

Use the marginTop property in JavaScript, to set the top margin. Can you try to run the following code to set the top margin of an element with JavaScript? Example             #myID {        border: 2px solid #000000;      }              This is demo text.    Add top margin          function display() {        document.getElementById("myID").style.marginTop = "150px";      }       

Read More

Is their a JavaScript Equivalent to PHP explode()?

Ankith Reddy
Ankith Reddy
Updated on 23-Jan-2020 2K+ Views

The JavaScript equivalent to PHP explode() is split(). To get the data after the first colon, try to run the following code.Example                    var str = '087000764008:Rank:info:result';          var arr = str.split(":");          document.write(arr[1] + ":" + arr[2]);          

Read More

Match any single character outside the given set.

Rama Giri
Rama Giri
Updated on 20-Jan-2020 138 Views

To match any single character outside the given set with JavaScript RegExp, use the [^aeiou] metacharacter.Example           JavaScript Regular Expression                        var myStr = "Welcome!";          var reg = /[^lc]/g;          var match = myStr.match(reg);                   document.write(match);          

Read More

Match any string containing a sequence of two to three p's.

Akshaya Akki
Akshaya Akki
Updated on 20-Jan-2020 141 Views

To match any string containing a sequence of two to three p’s with JavaScript RegExp, use the p{2,3} Quantifier.Example           JavaScript Regular Expression                        var myStr = "Welcome 1, 10, 100, 1000, 1000";          var reg = /\d{2,3}/g;          var match = myStr.match(reg);                    document.write(match);          

Read More

Debugging JavaScript using Firebug

Sharon Christine
Sharon Christine
Updated on 20-Jan-2020 861 Views

Debugging is the systematic method of removing defects. It all starts with execution of test cases. Whenever test cases are executed, the actual results are compared with expected results. If there is any lack of correspondence between the actual results and expected results, root cause analysis is done and additional tests such as regression tests are performed so as to ensure that the results are along the expected lines.To design static web pages, HTML is widely used. To develop dynamic web-based applications, JavaScript, the scripting language of the web should be used. To make their code bug-free, programmers rely on ...

Read More

How can I add debugging code to my JavaScript?

Krantik Chavan
Krantik Chavan
Updated on 17-Jan-2020 249 Views

To add debugging code to JavaScript, use the alert() or document.write() methods in your program. For example,var debugging = true; var whichImage = "widget"; if( debugging ) alert( "Calls swapImage() with argument: " + whichImage ); var swapStatus = swapImage( whichImage ); if( debugging ) alert( "Exits swapImage() with swapStatus=" + swapStatus );Examine the content and order of the alert() as they appear, you can examine the health of your program very easily.

Read More

How much should be a JavaScript Line Length?

Nitya Raut
Nitya Raut
Updated on 17-Jan-2020 820 Views

Try to keep the length of lines less than 80 characters. This would make the code easier to read. Best practice is to move to next line using break if JavaScript statements aren’t fitting in a single line.In addition, move to next line only after a comma or operator. For example, you can add statement like this, with a break after operator,function display() {    var a = "";    a = a + isNaN(6234) + ": 6234";        a = a + isNaN(-52.1) + ": -52.1";    a = a + isNaN('') + ": ''";    document.getElementById("test").innerHTML = a; }

Read More

What is the difference between "strict" and "non-strict" modes of JavaScript?

Abhinanda Shri
Abhinanda Shri
Updated on 16-Jan-2020 1K+ Views

The “use strict” is a directive, which is a literal expression. It introduced in JavaScript 1.8.5. As the name suggests, “use strict” indicates that the code is to be executed in strict mode. Under non-strict, the code won’t execute won’t execute in strict mode.Let us declare strict mode. To declare, add the keyword “use strict” in the beginning. For global scope, declare it at the beginning of the script.           An error would come, since you have used a variable, but forgot to declare it       Press F8 to see the error.                "use strict";          a = 1;          

Read More
Showing 5161–5170 of 5,339 articles
« Prev 1 515 516 517 518 519 534 Next »
Advertisements