By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,089 Members | 2,254 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,089 IT Pros & Developers. It's quick & easy.

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

P: n/a
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?

Oct 19 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
Try taking out the semi colon at the end of the function call?
CK

"Eric-Sebastien Lachance" <es********@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
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?

Oct 19 '05 #2

P: n/a
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 ;)

Oct 19 '05 #3

P: n/a
Eric-Sebastien Lachance wrote:
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.

--
Rob
Oct 19 '05 #4

P: n/a
RobG wrote :
Eric-Sebastien Lachance wrote:
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:...');">...


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
--
remove blah to email me
Oct 20 '05 #5

P: n/a
Gérard Talbot wrote:
RobG wrote :
Eric-Sebastien Lachance wrote:
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:...');">...


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'.

--
Rob
Oct 20 '05 #6

P: n/a
Chris Kettenbach wrote:
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
Oct 21 '05 #7

P: n/a
Eric-Sebastien Lachance wrote on 20 okt 2005 in comp.lang.javascript:
<div id="headerimg"><div style="width: 100%; height: 100%; cursor:
hand; cursor: pointer;"
onclick="top.location.href('http://www.monamouchtim.com/');">&nbsp;</di
v></div>


onclick="top.location.href = 'http://www.monamouchtim.com/';"

href is not a function.

If .href() works in IE, then that is wrong.

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Oct 21 '05 #8

P: n/a
Thomas 'PointedEars' Lahn <Po*********@web.de> writes:
Chris Kettenbach wrote:
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.


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
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Oct 21 '05 #9

P: n/a
Lasse Reichstein Nielsen wrote:
Thomas 'PointedEars' Lahn <Po*********@web.de> writes:
Chris Kettenbach wrote:
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.


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
Oct 21 '05 #10

P: n/a
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?

;-)
--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Oct 22 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.