Open Bug 887660 Opened 12 years ago Updated 3 years ago

x in img.onclick refers to img.x rather than window.x

Categories

(Core :: DOM: Core & HTML, defect, P5)

22 Branch
defect

Tracking

()

UNCONFIRMED

People

(Reporter: dazetec, Unassigned)

References

()

Details

User Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:22.0) Gecko/20100101 Firefox/22.0 (Beta/Release) Build ID: 20130618035212 Steps to reproduce: Defined and img tag with an onclick event with multiple lines of code. <img alt="" src="images/prev.png" onclick='if (x==1) {x=12;} else {x=x-1;} document.getElementById("galerie").src="images/galerie/"+x+".jpg";' class="png" /> This worked last night but this morning, after Firefox updated, it didn't work anymore. Actual results: Nothing happened. It worked only after I defined a function before and called it with the onclick. My conclusion was the onclick doesn't work with multiple lines of coding anymore. I must mention I am not a programmer or maybe just a novice. Expected results: This was part of a gallery browsing sistem. It was supposed to change an img's src with onclick event when clicking the "previous" button. The code calculated which image is the previous one.
A regression from bug 878509? Maybe it's a time to remove these non-standard properties. Although they were once restored since Firefox 14 "for compatibility reasons", they cause other compatibility problem now. Bug 878509 was not about "x" and "y" but about "lowsrc".
Blocks: 878509
Flags: needinfo?(dazetec)
It does not work with Fx19 either. Same problem.
Flags: needinfo?(dazetec)
Component: General → DOM
OS: Windows 7 → All
Hardware: x86_64 → All
Summary: Since Firefox v 22.0, the onclick event doesn't seem to work with multiple code lines → x in img.onclick refers to img.x rather than window.x
Alternatively, we can try to experiment with making elements themselves not be part of the scope chain for attributes. This keeps biting us and there's no way for authors to do things "the right way" to avoid problems like this. Other than simply stop using on* markup attributes, which is a pretty big feature to lose.
I am willing to bet money that the web is full of onclick="form.submit()"...
What we could experiment with is having the object on the scope chain only expose a whitelist of properties from the node.
That was my thinking exactly. Stick an object on the scope chain with .value, .form and a couple of more properties like that.
I must mention: There is a problem with onclick and multiple lines of code ("onclick:'code1;code2;code3..'"), but "<script> function func() code1; code2; code3; </script> ...onclick='func{}'..." works.
https://bugzilla.mozilla.org/show_bug.cgi?id=1472046 Move all DOM bugs that haven't been updated in more than 3 years and has no one currently assigned to P5. If you have questions, please contact :mdaly.
Priority: -- → P5
Component: DOM → DOM: Core & HTML
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.