Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Javascript Articles
Page 517 of 534
How to disable browser's back button with JavaScript?
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 MoreHow to create SVG graphics using JavaScript?
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 MoreHow to set the top margin of an element with JavaScript?
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 MoreIs their a JavaScript Equivalent to PHP explode()?
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 MoreMatch any single character outside the given set.
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 MoreMatch any string containing a sequence of two to three p's.
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 MoreDebugging JavaScript using Firebug
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 MoreHow can I add debugging code to my JavaScript?
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 MoreHow much should be a JavaScript Line Length?
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 MoreWhat is the difference between "strict" and "non-strict" modes of JavaScript?
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