This is a very simple code, but I'm having trouble running it in IE.
This html file with the javascript code is stored locally on my desktop. When I open the file using IE,..after clicking on the "this is a header" I do not get the alert message. However, in Firefox, it is working perfectly. The code is below,...
%26lt;html%26gt;
%26lt;head%26gt;
%26lt;script type="text/javascript"%26gt;
function getValue()
{
var x=document.getElementById("myHeader")
alert(x.innerHTML)
}
%26lt;/script%26gt;
%26lt;/head%26gt;
%26lt;body%26gt;%26lt;div id="myHeader" onclick="getValue()"%26gt;This is a header%26lt;/div%26gt;
%26lt;p%26gt;Click on the header to alert its value%26lt;/p%26gt;%26lt;/body%26gt;
%26lt;/html%26gt;
My Javascript code works in IE but not in Firefox?microsoft.com
I tested your code in both Firefox 2 and IE 7, and it worked fine in both. Do you have your security settings set too high?
My Javascript code works in IE but not in Firefox?internet browser internet explorer
Yup! That's true, not all the java scripts can be activated in firefox. Even it's for security purpose it's not working unless you use a software for it.
hi andrew!
i don't see any semi-colon ' ; ' in ur javascript statements above.
i think firefox might not be checking for strong syntax check
just include the ' ; ' (semi-colon) in ur 2 lines of the function and see if it works.
Running anything "local" will not guarantee that it will run on a server!
Upload your files to a server, then check with IE5/6/7, Firefox, Opera and Netscape (98.5% users total).
Use these in your code (javascripts in header)
To get all the details of the browser:
Global first:
var browser = "NC";
Functions:
function getbrowser_details()
{
var x = navigator;
var txt = "CodeName = " + x.appCodeName + "%26lt;br%26gt;";
txt += "MinorVersion = " + x.appMinorVersion + "%26lt;br%26gt;";
txt += "Name = " + x.appName + "%26lt;br%26gt;";
txt += "Version = " + x.appVersion + "%26lt;br%26gt;";
txt += "CookieEnabled = " + x.cookieEnabled + "%26lt;br%26gt;";
txt += "CPUClass = " + x.cpuClass + "%26lt;br%26gt;";
txt += "OnLine = " + x.onLine + "%26lt;br%26gt;";
txt += "Platform = " + x.platform + "%26lt;br%26gt;";
txt += "UA = " + x.userAgent + "%26lt;br%26gt;";
txt += "BrowserLanguage = " + x.browserLanguage + "%26lt;br%26gt;";
txt += "SystemLanguage = " + x.systemLanguage + "%26lt;br%26gt;";
txt += "UserLanguage = " + x.userLanguage;
return(txt);
}
To get the browser "ID":
function getbrowser()
{
var x = navigator;
var Name = x.appName;
var UA = x.userAgent;
if (Name.match("icrosoft"))
browser="IE";
else if (Name.match("pera"))
browser="OP";
else if (UA.search("avigat") %26gt; 0)
browser="NS";
else if (UA.search("irefox") %26gt; 0)
browser="FF";
else if (UA.search("afari") %26gt; 0)
browser="SF";
else
browser="NC";
}
If the browser is "NC", it is not compliant with W3C rules...
Say so!
function non_compliant()
{
var txt = "Sorry, your browser is not compliant with Web 2.0 ";
txt += "Use IE6, IE7, Firefox, Opera or Netscape";
alert (txt);
}
Get the width of the screen:
function GetW()
{
var myWidth = 0;
if( typeof( window.innerWidth ) == 'number' )
//Non-IE
myWidth = window.innerWidth -20;
else if ( document.documentElement %26amp;%26amp; (
document.documentElement.clientWidth ||
document.documentElement.clientHeight ) )
{
//IE 6+ in 'standards compliant mode'
myWidth =
document.documentElement.clientWidth - 16;
}
else if ( document.body %26amp;%26amp;
( document.body.clientWidth
|| document.body.clientHeight ) )
{
//IE 4 compatible
myWidth = document.body.clientWidth - 16;
}
return (myWidth);
}
Call these functions at the beginning of the %26lt;body%26gt; tag.
Note that some browsers respond to "body.clientWidth", while others respond to "documentElement.clientWidth".
Look for "innerHTML" as well: there are 3 different ways of getting the internal HTML...
No comments:
Post a Comment