Last Comment Bug 668223 - Firefox 5: Div onclick() doesn't work
: Firefox 5: Div onclick() doesn't work
Status: VERIFIED FIXED
:
Product: Core
Classification: Components
Component: DOM (show other bugs)
: 5 Branch
: All Windows 7
: -- normal (vote)
: mozilla7
Assigned To: Nobody; OK to take it and work on it
:
Mentors:
Depends on: 666604
Blocks: 583514
  Show dependency treegraph
 
Reported: 2011-06-29 08:18 PDT by Shawn
Modified: 2011-09-01 04:53 PDT (History)
7 users (show)
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Attachments
Test case containing all 3 examples given by the reporter (1.07 KB, text/html)
2011-09-01 00:12 PDT, Ioana (away)
no flags Details
Test case containing all 3 examples given by the reporter (1.33 KB, text/html)
2011-09-01 04:53 PDT, Ioana (away)
no flags Details

Description Shawn 2011-06-29 08:18:28 PDT
User Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
Build ID: 20110413222027

Steps to reproduce:

Updated browser to Firefox 5.


Actual results:

I have a div control that uses an onclick() event that has worked perfectly in prior versions of Firefox (verified in 4.0.1) and works correctly in all versions of IE.  However, on machines that have updated to Firefox 5, the onclick() event no longer works.


Expected results:

Clicking the div should have fired the onclick() event.
Comment 1 Boris Zbarsky [:bz] 2011-06-29 11:24:14 PDT
This works fine as far as I can tell.  Can you attach a testcase showing the problem, please?
Comment 2 Shawn 2011-07-01 06:21:24 PDT
You just want some markup?
Comment 3 Shawn 2011-07-01 06:41:12 PDT
<div onclick='transferPageWithReferrer(SOMEPAGE)'/>

The div is showing the hand cursor and I can see the correct location of the transferPageWithReferrer in the page source but on mouseover.  We've had several of our products indicate similar issues.

I've added an alert to the onclick event and it appears the onclick() event actually is being fired, but in this instance we are injecting an anchor tag to the page using document.createElement("a") and perhaps this is where the break is occurring.
Comment 4 Shawn 2011-07-01 07:27:11 PDT
ok so it appears that the Firefox issue is actually with the following rather than the onClick() event.  It appears that the issue is the

function transferPageWithReferrer(url) {
location.href = url;
}

is not working in Firefox 5.
Comment 5 Boris Zbarsky [:bz] 2011-07-01 07:48:35 PDT
> You just want some markup?

Generally, yes.  When filing a bug, it's a good idea to provide a link to a page showing the problem or attach the markup using the "Add an attachment" link.

I really doubt that you code looks like what you pasted in comment 4, especially given the business about createElement("a") in comment 3, which is conspicuously absent from comment 4.

Does it perhaps look more like bug 666985 comment 5?
Comment 6 Shawn 2011-07-01 08:15:33 PDT
lol... that's exactly where its breaking:

function navigateWithReferrer(url) {
        var fakeLink = document.createElement("a");
        if (typeof (fakeLink.click) == 'undefined') {
            location.href = url
        } else {
            fakeLink.href = url;
            document.body.appendChild(fakeLink);
            fakeLink.click()
        }
    }

Another developer used this approach to forward a page from a div onclick() event.
Comment 7 Shawn 2011-07-01 08:25:50 PDT
It seems that changing the above to: 

function navigateWithReferrer(url) {
        var fakeLink = document.createElement("a");
        if (document.createEvent) {
            location.href = url
        } else {
            fakeLink.href = url;
            document.body.appendChild(fakeLink);
            fakeLink.click()
        }
    }

has corrected the problem and the links are transferring again.
Comment 8 Boris Zbarsky [:bz] 2011-07-01 08:35:31 PDT
I have to ask... why are you not just always setting location.href?  What browser doesn't send a referrer on location.href sets?

In any case, the fix for bug 666604 fixed this.
Comment 9 Shawn 2011-07-01 08:49:22 PDT
believe it or not, location.href actually has a minor to moderate performance difference over this method.  Not sure why.  I actually took out all of the above and just used document.location.href = url and although the transfer occurred in both FF and the IE browsers, it took them awhile.

Thanks for your help.
Comment 10 Boris Zbarsky [:bz] 2011-07-01 08:52:30 PDT
> believe it or not, location.href actually has a minor to moderate performance
> difference 

Having measured and profiled both, I do not in fact believe it... ;)
Comment 11 Shawn 2011-07-01 08:57:41 PDT
:)
I wouldn't have thought so either, but, at least in this instance, it was sometimes up to 20-30 seconds difference.

Glitch in the matrix I suppose.
Thanks for all the help.
Comment 12 Ioana (away) 2011-09-01 00:12:57 PDT
Created attachment 557431 [details]
Test case containing all 3 examples given by the reporter
Comment 13 Ioana (away) 2011-09-01 00:16:21 PDT
Verified fixed on:
Mozilla/5.0 (Windows NT 6.1; rv:7.0) Gecko/20100101 Firefox/7.0
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:7.0) Gecko/20100101 Firefox/7.0

Steps to verify:
 1. Open the test case attached in the previous comment.
 2. Tap on each “Click here...” string (each string represents a different div with a distinct onclick method).
The corresponding web page is opened for each div (1-google.com, 2-gmail.com, 3-yahoo.com).
Comment 14 Ioana (away) 2011-09-01 04:53:15 PDT
Created attachment 557460 [details]
Test case containing all 3 examples given by the reporter

Note You need to log in before you can comment on or make changes to this bug.