Tag Archives: javascript

Asynchronous vs synchronous in javascript

you often see the terms asynchronous and synchronous in javascript. there is significant difference between the 2 and it affects the way you code. When executing something synchronously, you wait for it to finish before moving on. When executinge something asynchronously, you move on to the next task before it finishes. google map geocoding is … Continue reading

Delaying until condition is fulfilled

In javascript, we can use setTimeout to do call itself recursively until a condition is met. Here, we want to check the html content with an interval of 300ms until it is populated, then we will do something.

Simple way to redirect user if Mobile

Javascript can detect screen size and redirect users if they are using mobile. I’ve found that checking the screen size and redirecting users based on that can cover 99% of the use cases rather than injecting some complicated browser detection javascript libraries. The screen width of IPAD is 768px and screen width of a bigger … Continue reading

Opening and controlling a new popup window

we can assign a var to the window.open method and control the popup. but in order for it to work, remember to use to “opener” method or else it will fail in firefox. for example, var d = window.open(‘../popup/’+url,  ‘popup’, ‘width=1024, height=1024, scrollbars=1’); d.opener.location.reload(true);

quick and simple ajax loading or please wait screen

Traditionally, you would show an animated gif when doing ajax call to let user know that they have to wait to see some results. We do this by showing and hidding the animated gif in a div for example. Actually if you are rushing for time, a quicker and simpler solution is to change the … Continue reading

Javascript: check if url is a substring of another url

If I want to find out is a url is a substring of another url, for example whether http://blarblar.com/?abc=1 is a substring of http://blarblar.com/?abc=1&page=2&r=3 doing a indexOf or substr wouldn’t work because there are special characters in the string. Javascript does not yet have proper library to do this, we have to either depend on … Continue reading

submitting a form using hyperlinks

If using hyperlink to submit form, remember to return false in “onclick” so that it is backward compatible with IE6, ie <a class=”button_next” href=”javascript:;” onclick=”$(‘#form_wizard’).submit();return false;”> <span>Update</span> </a>