Home > JavaScript (page 3)


Javascript for loop vs jQuery for each

Javascript for loop vs jQuery for each Web developers often come across looping through data at client side. People generally use native Javascript coding for loop, or jQuery for each. Javascript For Loop. Example var names= ["jkoder", "kumar", "temp"]; var i; var text=""; for (i = 0; i < cars.length; i++) { text += names[i] + ","; } document.write(text); Result-> ... Read More »

Detecting key press for input text and Detecting Enter key


Detecting keypress for input text and Detecting Enter key The order of events related to the keyup event: 1. keydown – The key is on its way down2. keypress – The key is pressed down3. keyup – The key is released The keyup event occurs when a keyboard key is released. The keyup() method triggers the keyup event, or attaches ... Read More »

Using strict mode to write secure Javascript


Using strict mode to write secure Javascript We know that doing read operation from undeclared variable gives error in Javascript, whereas doing write operation to an undeclared variable is fine and the variable gets the global scope (I will discuss this in a different post as to why this happens in Javascript). Now, lets take stock of a situation in ... Read More »

Javascript Browser back button handling


Javascript Browser back button handling In Javascript getting handle of browser back button event is complex. There are many plugIns available to satisfy this complex need. However, I cam across a solution which to some extent can resolve this issue. if (window.history && window.history.pushState) { if(location.hash.split("#")[1]!='search'){ window.history.pushState('forward', null, '#search'); } } This piece of code will first do a forward ... Read More »

How to handle jQuery cross domain AJAX request

Cross Domain jQuery AJAX request AJAX Requests are only possible if port, protocol and domain of sender and receiver are equal, means that the following below listed requests won’t work- Requesting https://serverA.com/a.php from http://serverA.com/b.php Requesting http://subdomain.serverA.com from http://serverA.com Requesting http://serverA.com:5000 from http://serverA.com Here in this tutorial we will cover the ways to handle this restriction. First lets look at the ... Read More »