/    Sign up×
Community /Pin to ProfileBookmark

Non-working functions in .js file

I’ve collected some of the functions I use regularly in a .js file. To make sure they worked, I made a HTML file with alert() s. But none of the alert() s work.
I can’t see whats wrong.
Does anybody else know what may be wrong?

Here are the files:
[URL=http://jonhoo.web.surftown.nu/functions.js]The .js file[/URL]
[URL=http://jonhoo.web.surftown.nu/functionsTest.htm]The HTML file[/URL]

Jon

to post a comment
JavaScript

22 Comments(s)

Copy linkTweet thisAlerts:
@pj59Jan 13.2005 — Hello!

You need to delete a semi-colon quite at the end of the .js file (in this line):

for (var current_number_of_questions = 0; current_number_of_questions < number_of_questions; current_number_of_questions++[COLOR=red];[/COLOR])

Then your stuff will work (in IE, NOT in Mozilla).

Regards PJ
Copy linkTweet thisAlerts:
@KorJan 13.2005 — I don't think you want to alert a function... Probably you want to alert a variable, not a function

try in code

alert(the_language_to_return)

instead of

return the_language_to_return;

and

onClick="getLanguage();..."

instead of

onClick="alert(getLanguage());...

Same with the others

Yes, Moz probably will give an error message starting on line

else if (navigator.browserLanguage)
Copy linkTweet thisAlerts:
@JohnooauthorJan 13.2005 — Why doesn't it work in Opera or Mozilla? Is there a modification I could do to make it work in them too?

The HTML file is just a test to check if the functions will work when used on a real page. Therefore the alerts.

The return in the getLanguage function is simply because I am going to use the function for redirecting people to the page with their language
Copy linkTweet thisAlerts:
@pj59Jan 13.2005 — Hello!

If you "alert a function", its' return value will be alerted (if there is none, 'undefined' will be alerted). That is no problem. To get the stuff to work in Mozilla, Johnoo will have to replace all instances of '};' with ';}'. That's the reason why Mozilla complains.

Regards PJ
Copy linkTweet thisAlerts:
@KorJan 13.2005 — i was confusing, I reckon... I meant it would be easier to call a single function, to call all the other functions inside it (or move the codes in there), and to put the alerts (or to do whichever else) inside the code... ?
Copy linkTweet thisAlerts:
@JohnooauthorJan 13.2005 — I tried opening the HTML page in Opera, but when i press Start, nothing happens. Is this the same problem as the one in Mozilla?

pj59, I didn't understand what you were trying to say. How do I make the functions compatible with Mozilla and Opera?
Copy linkTweet thisAlerts:
@pj59Jan 13.2005 — [i]Originally posted by Johnoo [/i]

[B]I tried opening the HTML page in Opera, but when i press Start, nothing happens. Is this the same problem as the one in Mozilla?



pj59, I didn't understand what you were trying to say. How do I make the functions compatible with Mozilla and Opera? [/B]
[/QUOTE]
It is the same problem in Opera and Mozilla. All your if and else if statements end with [COLOR=red]};[/COLOR] - just replace that with [COLOR=blue];}[/COLOR] or simply [COLOR=blue]}[/COLOR] and it will work.

Regards PJ
Copy linkTweet thisAlerts:
@JohnooauthorJan 13.2005 — Great, now it works, but Opera 7.54 gets identified as Microsoft Internet Explorer 7.54. How come?
Copy linkTweet thisAlerts:
@pj59Jan 13.2005 — Hi!

In your function findBrowser()

you are mising the '[COLOR=blue]=[/COLOR]':

if ((find_the_browser_name =[COLOR=blue]=[/COLOR] "Microsoft Internet Explorer") && (find_the_browser_version <= 4) && (find_the_browser_version < 7))

{return find_the_browser_name + " or higher";}

Apart from that: imagine what this will put out.

The other thing is, that Opera can be set to be identified as different browsers. This is not the case in your settings (due to the correct version number). If you want to identify Opera regardless of its' settings, you will have to modify your browser sniffing...

PJ
Copy linkTweet thisAlerts:
@JohnooauthorJan 13.2005 — Thanks.
Copy linkTweet thisAlerts:
@pj59Jan 13.2005 — You're welcome. ?

For safe detection of Opera, you can use:

if(typeof(window.opera)=='object'){

//code for Opera

}

else{

//code for the rest of the world

}

Regards PJ
Copy linkTweet thisAlerts:
@scragarJan 13.2005 — hey that's not fair, the best thing about opera is that you spoof people to manipulate stats or change it so when a site say's that it doesn't work you can go ahead and prove that it does(my college being a prime example, anyone else know of the dreaded webCT?)
Copy linkTweet thisAlerts:
@pj59Jan 13.2005 — And what's the advantage for an Opera user ('disguising' it, by having it identified as IE for instance) and a script then logically detects document.all as true and the person who wrote that script put IE only stuff inside?
Copy linkTweet thisAlerts:
@scragarJan 13.2005 — because some sites(like the dreaded webCT) direct all none IE users to another page saying your browser isn't good enough but you still want to keep javascript enabled, esspecialy the allowing the redirect scripts.
Copy linkTweet thisAlerts:
@pj59Jan 13.2005 — I know that there are not only malicious users but malicious programmers as well. But for a "genuine" programmer it might be helpfull to provide alternatives for (e.g.) Opera users, if he is able to really detect: hey, this user's browser is Opera, so I give him/her stuff which Opera is capable of dealing with. I don't see any[i]Originally posted by scragar [/i]

[B]hey that's not fair[/B][/QUOTE]
behind such a behaviour.

PJ
Copy linkTweet thisAlerts:
@scragarJan 13.2005 — OK, but opera has the idenity as option for a reason.

let's just agree to disagree on this OK?
Copy linkTweet thisAlerts:
@pj59Jan 13.2005 — [i]Originally posted by scragar [/i]

[B]OK, but opera has the idenity as option for a reason.



let's just agree to disagree on this OK? [/B]
[/QUOTE]
No - never! ?

Because I agree with you that this option is absolutely justified and reasonable. :p

If we need to have a disagreement on something, let's invent one.

PJ
Copy linkTweet thisAlerts:
@scragarJan 13.2005 — like what?

it has to be about the net, preferably about browsers...
Copy linkTweet thisAlerts:
@pj59Jan 13.2005 — Just a suggestion:

My default browser is IE. ?

Shouldn't that be enough??

PJ
Copy linkTweet thisAlerts:
@scragarJan 13.2005 — arg! And to think I thought you knew how to get a good browser(firefox, pheonix, mozilla or opera are recomended).

You should change it, at the moment your a sitting duck for anything malicious. did you know that a virus can be encoded into an image so when IE reads it it becomes live(and strangly uses the cache as a home) yet no other browser has this flaw? or that IE spends 6 months after anouncing a flaw to get a reasonable patch?
Copy linkTweet thisAlerts:
@pj59Jan 13.2005 — [i]Originally posted by scragar [/i]

[B]arg! And to think I thought you knew how to get a good browser(firefox, pheonix, mozilla or opera are recomended).[/B][/QUOTE]
I just posted that because we needed something to disagree on. ?

Actually I do have 1 Mozilla, 3 NS, 2 Opera and one Firefox version. And IE is my default browser, because it is (which I am not happy about) by far the most used browser. The media in my country (Germany) have just begun to support Firefox. Hopefully, many more people here and wherever else will start using browsers other than the one which much too often is already installed when they purchase there machine.

I better stop here, because I don't want to loose the reason for our "disagreement" ?

PJ
Copy linkTweet thisAlerts:
@JPnycJan 13.2005 — [i]Originally posted by scragar [/i]

[B]hey that's not fair, the best thing about opera is that you spoof people to manipulate stats or change it so when a site say's that it doesn't work you can go ahead and prove that it does(my college being a prime example, anyone else know of the dreaded webCT?) [/B][/QUOTE]


Actually I think that's one of the worst things a browser can do. Completely messes up responsible developers who actually take the time to code for each major browser out there. That cloaking bit can be a real monkey wrench, so a way to get around it is absolutely necessary. Fortunately, ways do exist.
×

Success!

Help @Johnoo spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...