Closed Bug 12433 Opened 25 years ago Closed 25 years ago

Javascript OnClick handler does not work from a xul file

Categories

(Core :: Layout, defect, P3)

x86
Windows NT
defect

Tracking

()

VERIFIED WORKSFORME

People

(Reporter: morse, Assigned: joki)

References

Details

Copy the content below into the two files called x.xul and x.js. Bring up x.xul in the browser window. Click on the text that says "Click here". You get an assertion failure (debug builds only) but we already know about that (see bug 10441). Continue execution from the failure. The word "Thanks" is supposed to appear but it does not -- instead the "Click here" text remains on the screen. This works correctly from an html file as shown in bug 12432 (but it had other problems). Here are the files: 1. x.xul: <?xml version="1.0"?> <!DOCTYPE window> <xul:window xmlns="http://www.w3.org/TR/REC-html40" xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> <script src="x.js"/> <frameset rows = "20,10" onload="load1();"> <frame src="about:blank"/> <frame src="about:blank"/> </frameset> </xul:window> 2. x.js: function load1(){ top.frames[0].document.open(); top.frames[0].document.write( "<a onclick='top.load2();' href=''>Click here</a>" ); top.frames[0].document.close(); } function load2(){ top.frames[0].document.open(); top.frames[0].document.write( "Thanks" ); top.frames[0].document.close(); }
Blocks: 7530
Severity: normal → blocker
Nisheeth, this bug is blocking our development.
Status: NEW → ASSIGNED
Target Milestone: M10
Setting status to assigned and target milestone to M10. I'll take a look at this today.
Assignee: nisheeth → joki
Status: ASSIGNED → NEW
OK, after much poking around in DOM event handling land, here's what I've found. The load1() function does a document.write of the <a onclick='top.load2();' href=''> tag after x.xul loads. nsGenericHTMLElement::SetAttribute() processes the attributes on the <a> tag, sees the onclick handler and calls nsGenericElement::AddScriptEventListener(). This method calls the event listener manager's AddScriptEventListener() method. Inside nsEventListenerManager::AddScriptEventListener() (snippet is pasted below), the GetPrincipal() method fails and we abort out of the method without adding any event listener for the onclick event. if (global && NS_SUCCEEDED(global->QueryInterface(kIScriptGlobalObjectDataIID, (void**)&globalData))) { if (NS_FAILED(globalData->GetPrincipal(& prin))) { NS_RELEASE(global); NS_RELEASE(globalData); return NS_ERROR_FAILURE; } prin->ToJSPrincipal(& jsprin); NS_RELEASE(globalData); } I'm assigning this to Tom Pixley, the events god for further debugging.
*** Bug 12042 has been marked as a duplicate of this bug. ***
Blocks: 10240
Okay, is it just me or did this fix itself? I was going to fix it but suddenly found it working. Mind you we hit an error in nsHTTPChannel::Open() immediately afterwards but the 'Thanks' shows up so it would seem the handler is being registered. I'll let someone who has seen the behavior before verify this before I mark it fixed.
Status: NEW → RESOLVED
Closed: 25 years ago
Resolution: --- → WORKSFORME
Yes, it is working properly now. Thanks, joki, you have the magic touch. I'll mark it closed. With this fixed, I was now able to finish the conversion of my htlm viewers to xul and they are all working fine. I'm unblocked.
Status: RESOLVED → VERIFIED
In the Sept 2nd , its working for me as weel.
In the Sept 2nd , its working for me as well.
You need to log in before you can comment on or make changes to this bug.