Thursday, April 29, 2010

Browser Detection Javascript

Hello ... You may tired of searching javascript for browser detection. For your best use i've given below very neat javascript.

<script type="text/javascript">
var browsername = navigator.appName;
var browserversion = navigator.appVersion;
var browserdetail = browsername+browserversion;
if (browserdetail.indexOf(' ')!=-1)
{
alert(its working!);
}
</script>

Inside indexOf(''), you can mention the browser name with version (e.g. MSIE 6.0).

thank you ... bye

Wednesday, April 7, 2010

CSS style attributes in Javascript

We often confused when using style attributes in java script.
I below listed the attribute names in java script equivalent to css.

line-height ---- lineHeight
text-align ---- textAlign
text-decoration ---- textDecoration
text-indent ---- textIndent
text-transform ---- textTransform

vertical-align ---- verticalAlign

font-family ---- fontFamily
font-style ---- fontStyle
font-variant ---- fontVariant
font-weight ---- fontWeight

list-style ---- listStyle

color ---- color
background-color ---- backgroundColor

margin-top ---- marginTop
margin-right ---- marginRight
margin-bottom ---- marginBottom
margin-left ---- marginLeft

Using indexof in Javascript

Hi all,
You know well about -

indexof() returns the position of first occurrence of a specified value.


window.self.location returns the path of the window.



<script type="text/javascript">
var url = ''+ window.self.location;
if (url.indexOf('yoursite.com')!=-1)
{
document.getElementById('wrapper').style.backgroundColor ='green';
//You can modify here
}
</script>