The toSource() function, which we talk about yesterday(Javascript – Print an object with alert()), only works in Firefox, a more proper way which work in non Gecko engine browser like Chrome and Safari is using console. Continue reading Javascript – Print an object in console
Category Archives: Javascript
Javascript – Print an object with alert()
During web development, sometimes we may need to print the whole Javascript object for debug purpose. You can simply dump the object to the alert box by toSource(). Continue reading Javascript – Print an object with alert()
Javascript – Add To Bookmark
I found a Javascript which is for adding bookmark to browser. Since Chrome and Safari do not support adding bookmark by Javascript, an alert box will be prompted and tell the user using Ctrl + D to add the bookmark instead. Continue reading Javascript – Add To Bookmark
Javascript – Get URL Query String
We can obtain the URL query string with the following Javascript function. Continue reading Javascript – Get URL Query String
Javascript – Check string contains
We can use the indexOf() function to check if a string exists in another string.
var s = "foo";
alert(s.indexOf("oo") != -1);
it returns true if s contains “oo” and vice versa.
Done =)
Javascript – Preload Images When the HTML Page is Loaded
With Javasript and jQuery, we could manipulate images at client side. For example, some images are shown on a mouse hover effect. But if that image is too large, there may be some latency before the image could be rendered. We’d better preload those images to minimize the time delay. Continue reading Javascript – Preload Images When the HTML Page is Loaded
Javascript – Negative substr() problem in Internet Explorer
It is very common to extract part of a string in computer programming and there is no exception in Javascript. Here are 2 functions for string extraction
- aString.substr(start, length)
- aString.substring(start, stop)
Continue reading Javascript – Negative substr() problem in Internet Explorer
Javascript – Parse XML
I find a very good blog by Steve Born about parsing XML in Javascript. There are all together 3 different ways to parse XML but not all of them are mutually compatible with all browsers. Continue reading Javascript – Parse XML
jQuery & Javascript – Capture the Browser or Tab Closed Event
I was working on a WordPress project which i need to clear the PHP session when the browser or browser tab is closed. Although Javascript provides the window.onbeforeunload event but it will be triggered even whenever you leave the website. Finally i got a simple solution from Daniel Melo in StackOverflow. The following code required jQuery and i have included the Google one in the HTML.
In your web root, create the js/check_browser_close.js. Continue reading jQuery & Javascript – Capture the Browser or Tab Closed Event
Ajax – Simple Ajax GET Request
This is another example of implementing simple Ajax GET request. Please refer to Ajax – Simple Ajax POST Request for a POST request. Actually, both of them are quite similar and it is good to try both to get more familiar with the generic Ajax requests.
Let’s start our example now. Continue reading Ajax – Simple Ajax GET Request