homepage Welcome to WebmasterWorld Guest from 54.237.54.83
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
My javascript worked in IE and Chrome, but not Firefox.
Javasctript, IE, Chrome, Firefox
Bucephalus




msg:4141574
 9:43 am on May 27, 2010 (gmt 0)

Hi

I'm doing an introductory javascript exercise on the msdn beginner's website. I'm using visual studio 2010, and here is the code.


<html>
<head>
<title>My page</title>
<script type="text/javascript" language="javascript">
<!--

function say(text)
{
alert(text);
}

say("The page is loading!");

//-->
</script>
</head>
<body>
<noscript>
JavaScript is turned off.
</noscript>

<input type="button" value="Click me!" onclick="say('Thanks for clicking!')" />

</body>
</html>


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?

David.

 

daveVk




msg:4141870
 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 ?

Fotiman




msg:4141880
 2:21 pm on May 27, 2010 (gmt 0)

Yeah, it sounds like a caching issue.

vol7ron




msg:4142012
 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.

Either:
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.

Bucephalus




msg:4142715
 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.

Cheers

Bucephalus




msg:4142726
 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?
regards
David.

Bucephalus




msg:4142731
 9:52 am on May 28, 2010 (gmt 0)

Hi, I played around with the cache by clearing it and I was getting some results, but it wasn't that consistent. I then saw that the browser toolbars were kind of loading in two stages. First the normal menus, and then the yahoo toolbar would load into the top of the browser. So I decided to uninstall that and see what happens, and now the browser works just like IE and Chrome for this javascript. I wonder how much this yahoo toolbar affects real javascript. Not sure if there is a way to fix this without installing this yahoo toolbar because I wouldn't want to be writing code that works on the condition that the user doesn't have yahoo toolbar installed on the browser.

Thanks for all your help.

David.

subexpression




msg:4143660
 7:25 pm on May 29, 2010 (gmt 0)

Bucephalus,

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.

The Yahoo! toolbar blocks popups...which includes Javascript alert() boxes.

So, here's the quick & skinny: Most people don't want to see a Javascript alert() box pop up in their face when they first load a page...it's annoying.
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!
Keep on writing Javascript my friend...it's a great language :)

Bucephalus




msg:4143757
 11:50 pm on May 29, 2010 (gmt 0)

Thanks for your support.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved