Javasctript, IE, Chrome, Firefox
| 9:43 am on May 27, 2010 (gmt 0)|
say("The page is loading!");
<input type="button" value="Click me!" onclick="say('Thanks for clicking!')" />
Well what happens in IE and Chrome, which is, I'm pretty sure the expected behaviour is this:
I right click on the document in visual studio and select "view in browser".
The browser displayes with a little message box with a button on it saying, "The page is loading!".
When I click this button the message box disappears and a button appears in the top left corner of the page. When I click on this button, a new message box appears that says, "Thanks for clicking!"
Well that's it, and that happens for CHrome and IE, but for firefox, when I change firefox to the default browser so I can use the "View in Browser" functionality of VS 2010, it works the first time. but every other time I try to do it in Firefox it just immediately goes to the page with the button in the top left-hand corner. I.e. the first message box with the "The page is loading!" message doesn't show.
Does anybody have an idea why I would get this different behaviour in Firefox?
| 2:12 pm on May 27, 2010 (gmt 0)|
I guess Firefox says, I already have this page loaded and displayed, so save time and don't reload it. I have never used VS 2010, does it do the same thing not using VS 2010 ?
| 2:21 pm on May 27, 2010 (gmt 0)|
Yeah, it sounds like a caching issue.
| 4:04 pm on May 27, 2010 (gmt 0)|
Instead of having a global function call, try adding it to the window's onload function.
1) change the body tag:
<body onload="say('The page is loading!');">
2) change the script
window.onload='say("The page is loading!")';
Note: there are other ways to attach events, but for this introductory course, the two above use the least advanced method.
The last Visual Studio I had was VS2005, and it's been a while since I've used it. So you know, there's a big difference from rendering the page w/in VS as Firefox, rather than opening the page directly in the Firefox browser. Certain events like these may be cached, or even bypassed.
| 9:27 am on May 28, 2010 (gmt 0)|
yeah ok, thanks for your replies.
I will give it a go without the visual studio. I will let you know what happens.
| 9:34 am on May 28, 2010 (gmt 0)|
Unfortunatly, it's doing the same thing outside of VS.
I just went into the windows file system and found the file and opened it with firefox.
Same result. So if it is a caching issue, is it fixable?
| 9:52 am on May 28, 2010 (gmt 0)|
Thanks for all your help.
| 7:25 pm on May 29, 2010 (gmt 0)|
I placed your code in an HTML file on my desktop, dragged it into Firefox (version 3.6.3), and it works fine every time. Reloading displays the first alert() function call, and clicking the input button displays the second alert()
Personally, I never use toolbars except for the Firefox Web Developer Toolbar addon.
For your exercise, it works...just trust that it does.
But, for the future, don't use alert() pop up messages that launch from the initial page load.
Many users have popup blockers (including the Y! toolbar)...and many people hate being greeted by a happy little alert box.
Just trust that your script works fine...good job for entry-level scripting!
| 11:50 pm on May 29, 2010 (gmt 0)|
Thanks for your support.