Tuesday, September 20, 2011

JS 101: How to get URL parameters from HTML page

Same with PHP or ASP page, HTML will be able to get the query string parameters but not that as easy compare to PHP and ASP.

We can get it by parsing the URL parameters via javascript, and to help you with, I created a script below that does it.

The script will parse and get the "spage" parameter of the HTML page and prompt it via alert dialog box. Sample URL will be.. index.htm?spage=1..

var spage = getUrlParam("spage");
alert(spage);

function getUrlParam(param)
{
    var hash = [];
    var value = '';
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    

    for(var i = 0; i < hashes.length; i++) { 
        hash = hashes[i].split('='); 
        if (hash[0] == param) value = hash[1]; 
    } 

    return value;
}

Hope you like it!!

Sunday, September 18, 2011

IE 101: Misalignment of element on IE browsers

In web development, most developers have issues on IE compatibility. One of the problem I encountered are the misalignment of the element in IE browser, specially the IE8.

This is due to the styling you made on alignment. We normally use vertical alignment in CSS to align our element vertically.

Problem here is that the value "text-top" is not working on IE8. Hence, you have to use "top" instead, which is the same behavior with "text-top".

In your CSS entries, instead of using this one:

vertical-align: text-top;

You have to use this one:

vertical-align: top;


Hope this helps.

I'll be posting more of IE issues to help other developers to get through with it. Follow IE 101 for more of IE posts.