Simple <div onclick=""> not working in firefox

  • Thread starter Eric-Sebastien Lachance
  • Start date
E

Eric-Sebastien Lachance

Hey there,

I decided to just create a 100% height and width div that filled the
space over a background header image, and add an onclick event to
redirect to the my index... Doesn't seem to work in FireFox only, just
in IE. Here's the code:

<div id="headerimg"><div style="width: 100%; height: 100%; cursor:
hand; cursor: pointer;"
onclick="top.location.href('http://www.monamouchtim.com/');">&nbsp;</div></div>

This seems to work fine in IE, but doesn't in Firefox. Am I stupid or
am I missing something really important about FireFox?
 
E

Eric-Sebastien Lachance

Chris Kettenbach tried to help by typing:
Try taking out the semi colon at the end of the function call?
CK

Unfortunately, that doesn't seem to fix the problem... And that was a
php coder reflex ;)
 
R

RobG

Eric-Sebastien Lachance said:
Hey there,

I decided to just create a 100% height and width div that filled the
space over a background header image, and add an onclick event to
redirect to the my index... Doesn't seem to work in FireFox only, just
in IE. Here's the code:

<div id="headerimg"><div style="width: 100%; height: 100%; cursor:

Due to the differences in how Firefox and Mozilla implement the above
style, the size of your divs are quite different - but that's for a CSS
group to discuss.
hand; cursor: pointer;"
onclick="top.location.href('http://www.monamouchtim.com/');">&nbsp;</div></div>

This seems to work fine in IE, but doesn't in Firefox. Am I stupid or
am I missing something really important about FireFox?

Yes:

Tools --> JavaScript Console

It will tell you that 'top.location.href is not a function'. Use

<... onclick="location.href('http:...');">...

The terminating semi-colon is in accordance with JavaScript syntax,
though not required in this case.
 
G

Gérard Talbot

RobG wrote :
Due to the differences in how Firefox and Mozilla implement the above
style, the size of your divs are quite different - but that's for a CSS
group to discuss.



Yes:

Tools --> JavaScript Console

It will tell you that 'top.location.href is not a function'. Use

<... onclick="location.href('http:...');">...

Sorry but that's wrong.
The answer/solution is:

<div style="width: 100%; height: 100%; cursor: pointer;"
onclick="top.location.href = 'http://www.monamouchtim.com/';">&nbsp;</div>

or

<div style="width: 100%; height: 100%; cursor: pointer;"
onclick="self.location.href = 'http://www.monamouchtim.com/';">&nbsp;</div>

If the window is not in a frameset, then calling
top.location.href = 'http://www.monamouchtim.com/';
will be resolved as the calling window.
top means the topmost window in a frameset hierarchy; if there are no
frameset, then top == self. In a sense, the use of top instead of self
may also be better if used to prevent framing.

The problem with the code was the proper use of
location.href.
[window object reference].location.href('...some url')
and
[window object reference].location.href = '...some url';
are 2 different instructions; the first/former is a wrong function call
while the second/latter is an assignment.

Gérard
 
R

RobG

Gérard Talbot said:
RobG wrote :


Sorry but that's wrong.

*You're* sorry? :-x

Yeah, I corrected & tested it, then didn't copy & paste. Sloppy, but
there you are.

[...]
The problem with the code was the proper use of
improper?

location.href.
[window object reference].location.href('...some url')
and
[window object reference].location.href = '...some url';

Hence 'top.location.href is not a function'. Just illustrates the
difference between 'read the warning' and 'heed the warning'.
 
T

Thomas 'PointedEars' Lahn

Chris said:
Try taking out the semi colon at the end of the function call?

The JS engine does automatic semicolon insertion. Please don't
post here if you haven't really got a clue of what you are talking
about. Thank you.


PointedEars
 
L

Lasse Reichstein Nielsen

Thomas 'PointedEars' Lahn said:
The JS engine does automatic semicolon insertion. Please don't
post here if you haven't really got a clue of what you are talking
about. Thank you.

Then how will he be corrected and learn, like the rest of us did?

Don't be so dismissive. If only people with perfect knowledge posted,
there wouldn't be much traffic (and less point to it).

Personally, I prefer people without technical skills to people
without communications skills ... they are easier to tell where
they are mistaken :)
/L
 
T

Thomas 'PointedEars' Lahn

Lasse said:
Then how will he be corrected and learn, like the rest of us did?

I should have written "reply". What I meant is that such wild
guesses won't help anyone, they just waste everyone's bandwidth.
Don't be so dismissive. If only people with perfect knowledge posted,
there wouldn't be much traffic (and less point to it).

You misunderstand, I do know nobody's perfect, myself included. But at
least one should have a minimum clue on the topic before making assumptions
and providing help. There is a difference between wild, laymen guesses and
educated guesses. This one certainly was of the former.


PointedEars
 
E

Evertjan.

Thomas 'PointedEars' Lahn wrote on 21 okt 2005 in comp.lang.javascript:
You misunderstand, I do know nobody's perfect, myself included. But
at least one should have a minimum clue on the topic before making
assumptions and providing help. There is a difference between wild,
laymen guesses and educated guesses. This one certainly was of the
former.

Is this an educated assumption, Thomas?

;-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top