JavaScript function not firing in IE9 - javascript

I created a textbox and wrote onfocus="getFocus()" //"getFocus();" also not working.
Now I wrote function in JavaScript:
function getFocus()
{
alert('Hello I Got Focus !!');
}
The problem is in IE8 it worked perfectly, but in IE9 alert is not showing. Can anyone tell what is wrong with the following code?
I also tried:
txtAmt.Attributes.Add("onfocus","getFocus()")
txtAmt.Attributes.Add("onfocus","getFocus();") //also not working
but still it didn't worked
I too tried:
txtAmt.Attributes.Add("onfocus","javascript:getFocus();")
In Internet option ActiveScripting is also 'Enabled'
Now I am worried; what to do?

Please Make sure if java script is enabled in your browser .Enable it or rest
Go to tools -> internet options -> advanced -> reset and it'll go back to default after restart. Also restore advanced settings.

http://jsfiddle.net/TTxdK/ - tested in IE9 on Windows Vista, onfocus works

Related

alert() and console.log() not working in Firefox 26

I feel like I'm going crazy but alert() and console.log() refuses to work anywhere on Firefox 26.
At first I thought it was my own website's problem, but I cannot for the life of me to get it to work via javascript: urls, Firebug, I even tried it in jsfiddle.net by just putting alert('test'); in the script panel.
Tried uninstalling and installing again, no luck.
The only extension I'm running is Firebug.
Heck, Stackoverflow didn't even prompt me about leaving when I accidentally clicked the back button while writing this.
Also yes, I made sure there was some content inside the alert() and console.log()
What I mean by not working is that Firefox treats the code as if it were non-existent, nothing happens.
Once again, here's my environment:
Browser: Firefox 26.0
OS: Windows 8.1 Pro
Issue: alert(), console.log(), and apparently prompt() doesn't work
If anyone might know why this is happening, I would highly appreciate an answer.
UPDATE
Following Pointy's comment, it appears that both alert() and console.log() work as expected on the New Tab Page, but nowhere else
You might want to try re-installing Firebug:
console.log in firefox is not working?
PS:
I happen to be running a similar configuration (including FF 26) ... and things work fine for me. IMHO...
PPS:
You might also try setting "about:config, prompts.tab_modal.enabled = false":
https://bugzilla.mozilla.org/show_bug.cgi?id=613752
The default is "true", my FF 26 is set "true" and things are working for me ... but who knows. If reinstalling Firebug doesn't help, maybe it's worth a shot?
Silly but, in firebug can you check if window.alert and window.console are defined.... and if yes then, can you check if window.alert('hi') works ?
Thanks for all the help guys, in the end I used Revo Uninstaller to completely and absolutely wipe Firefox from my system, then installed it again. Seems to be working now, the original uninstaller most likely didn't remove whatever was causing the problem.
I have same bug when i using Ghostery extension. Disable Ghostery and reload page. Lets check at https://getfirebug.com/tests/head/console/api/log.html
I had a similar issue, on IE v11.0.10 and Chrome Canary v38.0.2114. Duplicate function name turnout to be the issue. Worth doing a quick check for function names in Javascript file.
You can use the Firefox console with CTRL + SHIFT + K
Related: https://support.mozilla.org/en-US/questions/876916

Click events and Google Chrome and Windows 8

I am trying to use the following JQuery code:
$("#thing").on("click", function() {
....})
And it doesn't work on Google Chrome in Windows 8, but it works in Firefox on Windows 8 and basically every other OS. Any ideas?
It works, check this: http://jsbin.com/ofuvuh/1 Probably there is some error in the code that ff ignore or maybe it's your browsers fault. Please check the chrome and ie console, probably it can helps
Try:
$("#thing").click(function ()
{
// your code here
});
Which is the same as .on('click', handler). See .click documentation.
Your code snippet looks completely fine. I assume you are using a fairly up to date version of jQuery, so most probably it is nothing to do with jQuery or the browser. I suspect there might be something wrong with the code surrounding your snippet.
As a possible solution:
In Chrome you can bring up the Console, which will tell you if there is any errors in your JavaScript (developers.google.com/chrome-developer-tools/docs/…). Open it up, refresh your page (you might see the error in the Console straight away). Or click that '#thing' and watch out for any possible errors coming up in the Console.

Binding handlers to events in IE

I'm trying to bind some functions to an event.
The following code works perfectly fine in Chrome and FF but what's the corresponding code for IE?
$this.mouseenter(function(){
console.log("inside the mouse enter handler");
});
I tried this but it didn't work in IE:
$this.bind('mouseenter', function(){
console.log("inside the mouse enter handler");
});
I need it to work in at least IE 9.
console.log or at least console will give you an error on IE... hence, your javascript will not work... try using alert...
Unable to understand what is wrong # your end.
I tried this and its working fine for me.
console.log will return a js error, if your browser's console is not open. It will happen in any browser, not only with IE. Probably you tried FF and chrome with the browser console open and IE without opening the browser console. Try opening the browser console open in IE as well / by using alert() to test your funcitonality / by directly writing the functionality that you need.
Hope it helps!!!

javascript redirect only works in IE after showing the IE dev console

I came across the weirdest bug. All i wanted to do is send a form using jquery and in the callback redirect the user to another page, like:
window.location.href = "index.php?p=admin";
Which from what i can find should work in all browsers.
And it does, except in IE8/9 where it only does that after i hit F12 to show the dev console! After that i need to close the browser for the redirect to NOT work again.
Anyone know why this happens and know a better way to redirect to another local page using javascript that works in IE without being affected by this crazy bug?
Are you using any of the console. functions? They aren't defined until showing the dev console and will stop the script from executing.
Have you tried?
window.location.replace("index.php?p=admin");

jQuery plugin Cross Slide and Internet Explorer

I am using the jQuery plugin Cross Slide. My page is working fine in Chrome and Firefox. But in Internet Explorer 7, I get:
Debug error as Object expected on line 1:
$(document).ready(function() {
$('#image').crossSlide({sleep:4,fade:1},[{src:'images/1.jpg'},{src:'images/2.jpg'}]);
});
How can I fix the bug for Internet Explorer 8 and Internet Explorer 7?
I had the same problem, you just have to delete the comma after the last picture you point to. This should work in IE.
Greets
Try with companion.js. It points you to the JavaScript line that has the problem instead of the default line 1. Moreover, try with unpacked JavaScript code so that you know what is wrong.
Could you provide more code or even better, a working page that reproduces the problem? That little piece of code looks fine so far...
By the way, the "on line 1" tells you absolutely nothing in IE, don't trust it.

Categories