Showing posts with label Browser. Show all posts
Showing posts with label Browser. Show all posts

Monday, October 4, 2010

How to detect browser using javascript

we can use navigator.userAgent to detect the type/name of current browser and perform compatibility operations according to it:

below is javascript code so put it in script tag


function DetectBrowser()
{

var val = navigator.userAgent.toLowerCase();



if(val.indexOf("firefox") > -1)

{

isFF = true;

}

else if(val.indexOf("opera") > -1)

{
isOP = true;

}

else if(val.indexOf("msie") > -1)

{

isIE = true;

}

else if(val.indexOf("safari") > -1)

{

isIE = true;

}
}
Read More

How to Detect the browser using asp.net and c#.net

Many of times we need to detect browser type/name and its capability in asp.net
to do so below code can help you:
These properties are exposed by the HttpBrowserCapabilities object indicate inherent capabilities of the browser,
*but do not necessarily reflect current browser settings.

so using Request.Browser.Browser we can find the name of browser and using if-else/switch-case we can perform desired operation for specific browser type or we can use these to find capabilities of current browser and do operations according to supported by browser.


Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim s As String = ""
With Request.Browser
s &= "Browser Capabilities" & vbCrLf
s &= "Type = " & .Type & vbCrLf
s &= "Name = " & .Browser & vbCrLf
s &= "Version = " & .Version & vbCrLf
s &= "Major Version = " & .MajorVersion & vbCrLf
s &= "Minor Version = " & .MinorVersion & vbCrLf
s &= "Platform = " & .Platform & vbCrLf
s &= "Is Beta = " & .Beta & vbCrLf
s &= "Is Crawler = " & .Crawler & vbCrLf
s &= "Is AOL = " & .AOL & vbCrLf
s &= "Is Win16 = " & .Win16 & vbCrLf
s &= "Is Win32 = " & .Win32 & vbCrLf
s &= "Supports Frames = " & .Frames & vbCrLf
s &= "Supports Tables = " & .Tables & vbCrLf
s &= "Supports Cookies = " & .Cookies & vbCrLf
s &= "Supports VBScript = " & .VBScript & vbCrLf
s &= "Supports JavaScript = " & _
.EcmaScriptVersion.ToString() & vbCrLf
s &= "Supports Java Applets = " & .JavaApplets & vbCrLf
s &= "Supports ActiveX Controls = " & .ActiveXControls & _
vbCrLf
s &= "Supports JavaScript Version = " & _
Request.Browser("JavaScriptVersion") & vbCrLf
End With
TextBox1.Text = s
End Sub

Reference Link:http://msdn.microsoft.com/en-us/library/3yekbd5b.aspx

Solution by:Rajesh Rolen

Read More

Thursday, September 23, 2010

Load XML using javascript [works with all browser]

When ever we wants to load and parse xml using javascript. we face a issue most of time is that the script works with one browser but not works with other.
Below script will work on all browsers including [safari,mizila firefox, crome]:


function loadxml() {
var xmlFeed = "xmldata/wfc20100915.xml";
if (window.ActiveXObject) {
var errorHappendHere = "Check Browser and security settings";
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async = false;
xmlDoc.load(xmlFeed);
}
else if (window.XMLHttpRequest) {
var errorHappendHere = "Error handling XMLHttpRequest request";
var d = new XMLHttpRequest();
d.open("GET", xmlFeed, false);
d.send(null);
xmlDoc = d.responseXML;
} else {
var errorHappendHere = "Error.";
xmlDoc = document.implementation.createDocument("", "", null);
xmlDoc.async = false;
xmlDoc.load(xmlFeed);
}


var tmp = readXML();

return tmp;
}
//below code is to read xml
function readXML() {

var labels = xmlDoc.getElementsByTagName('node');
arr = new Array();
var counter = 0;
for (i = 0; i < labels.length/ 10; i++) {
{
if (labels[i].childNodes.length >= 9) {
arr[counter] = new Array(5);
arr[counter][0] = parseFloat(labels[i].childNodes[1].textContent);
arr[counter][1] = parseFloat(labels[i].childNodes[3].textContent);
arr[counter][2] = parseFloat(labels[i].childNodes[5].textContent);
arr[counter][3] = parseFloat(labels[i].childNodes[7].textContent);
arr[counter][4] = parseFloat(labels[i].childNodes[9].textContent);
counter++;
}

}

return arr;

}


Solutions by: Rajesh Rolen

Read More

Monday, November 16, 2009

How to detect browser close button is clicked ?

call this function from page_unload() so when user will close the browser either by [X] button or by alt+f4 or from exit (from file menu). by using this function you can detect that browser is going to close and you can perform any of your choice operation just before browser get close.

function CheckBrowser()
{
// Check Browser Close [X] , Alt+F4 , File -> Close
if(window.event.clientX < 0 && window.event.clientY <0)
{
window.open("Operation.aspx",
"Operation",'left=12000,top=1200,width=10,height=1');
}
}
Read More
Powered By Blogger · Designed By Seo Blogger Templates