Connecting Tech Pros Worldwide Forums | Help | Site Map

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

Eric-Sebastien Lachance
Guest
 
Posts: n/a
#1: Oct 20 '05
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?


Eric-Sebastien Lachance
Guest
 
Posts: n/a
#2: Oct 20 '05

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


Chris Kettenbach tried to help by typing:[color=blue]
> Try taking out the semi colon at the end of the function call?
> CK
>[/color]

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

Chris Kettenbach
Guest
 
Posts: n/a
#3: Oct 20 '05

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


Try taking out the semi colon at the end of the function call?
CK

"Eric-Sebastien Lachance" <eslachance@gmail.com> wrote in message
news:1129763524.294815.123330@g14g2000cwa.googlegr oups.com...[color=blue]
> 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?
>[/color]


RobG
Guest
 
Posts: n/a
#4: Oct 20 '05

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


Eric-Sebastien Lachance wrote:[color=blue]
> 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:[/color]

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.
[color=blue]
> 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?[/color]

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
Gérard Talbot
Guest
 
Posts: n/a
#5: Oct 20 '05

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


RobG wrote :[color=blue]
> Eric-Sebastien Lachance wrote:
>[color=green]
>> 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:[/color]
>
>
> 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.
>[color=green]
>> 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?[/color]
>
>
> Yes:
>
> Tools --> JavaScript Console
>
> It will tell you that 'top.location.href is not a function'. Use
>
> <... onclick="location.href('http:...');">...
>[/color]

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
RobG
Guest
 
Posts: n/a
#6: Oct 20 '05

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


Gérard Talbot wrote:[color=blue]
> RobG wrote :
>[color=green]
>> Eric-Sebastien Lachance wrote:
>>[color=darkred]
>>> 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:[/color]
>>
>>
>>
>> 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.
>>[color=darkred]
>>> 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?[/color]
>>
>>
>>
>> Yes:
>>
>> Tools --> JavaScript Console
>>
>> It will tell you that 'top.location.href is not a function'. Use
>>
>> <... onclick="location.href('http:...');">...
>>[/color]
>
> Sorry but that's wrong.[/color]

*You're* sorry? :-x

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

[...][color=blue]
> The problem with the code was the proper use of[/color]

improper?
[color=blue]
> location.href.
> [window object reference].location.href('...some url')
> and
> [window object reference].location.href = '...some url';[/color]

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



--
Rob
Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a
#7: Oct 21 '05

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


Chris Kettenbach wrote:
[color=blue]
> Try taking out the semi colon at the end of the function call?[/color]

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
Evertjan.
Guest
 
Posts: n/a
#8: Oct 21 '05

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


Eric-Sebastien Lachance wrote on 20 okt 2005 in comp.lang.javascript:
[color=blue]
> <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>
>[/color]

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)

Lasse Reichstein Nielsen
Guest
 
Posts: n/a
#9: Oct 21 '05

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


Thomas 'PointedEars' Lahn <PointedEars@web.de> writes:
[color=blue]
> Chris Kettenbach wrote:
>[color=green]
>> Try taking out the semi colon at the end of the function call?[/color]
>
> 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.[/color]

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 - lrn@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a
#10: Oct 21 '05

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


Lasse Reichstein Nielsen wrote:
[color=blue]
> Thomas 'PointedEars' Lahn <PointedEars@web.de> writes:[color=green]
>> Chris Kettenbach wrote:[color=darkred]
>>> Try taking out the semi colon at the end of the function call?[/color]
>>
>> 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.[/color]
>
> Then how will he be corrected and learn, like the rest of us did?[/color]

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

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
Evertjan.
Guest
 
Posts: n/a
#11: Oct 22 '05

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


Thomas 'PointedEars' Lahn wrote on 21 okt 2005 in comp.lang.javascript:[color=blue]
> 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.[/color]

Is this an educated assumption, Thomas?

;-)


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

Closed Thread