Closed Bug 187479 Opened 23 years ago Closed 23 years ago

object event handling (not regular events) not working properly in dialogs

Categories

(Core :: XUL, defect)

x86
Windows 2000
defect
Not set
normal

Tracking

()

RESOLVED INVALID

People

(Reporter: dnfesp, Assigned: jag+mozilla)

Details

Attachments

(1 file)

User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.3a) Gecko/20021207 Phoenix/0.5 Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.3a) Gecko/20021207 Phoenix/0.5 I have reported this in the xpfe news group with no success. What I want to do is get some values using a dialog window and send them to a server using the XMLHttpRequest object, the result of the request is used to change a tree widget on the parent window. I'm posting here a very simplified version of what I'm trying to do. The parent window could be this: <window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"> <tree id="tree_w" flex="1" hidecolumnpicker="true" seltype="single" ondblclick="edit(this)"> ... </tree> </window> in a separate js file, an edit function is declared which opens up the dialog: function edit(tree) { window.openDialog("chrome://myApp/content/dialogs/test.xul", "no title", "chrome,modal"); } test.xul is a dialog like this: <dialog id="xxx" xmlns=http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"; title="xxx" width="580" height="150" persist="screenX screenY" ondialogaccept="return pressOK();" ondialogcancel="return true;"> <textbox id="valuetosend"/> </dialog> in a separate js file I have declared the pressOK() function: function pressOK() { var uri = 'http://localhost/home/test?value=' + document.getElementById('valuetosend').value; var req = new XMLHttpRequest(); req.open('GET', uri); req.send(null); req.onload = function() { // Here is where things gets strange, I cannot access the window object from this, neither the document nor any function like alert(), prompt(), etc... if (req.status == 200) { alert('this will not work'); parent.document.getElementById('tree_w').selectedIndex = req.responseText; // this will not work either, it cannot find the document object in the context of this function. // now suppose I wanted to call a function notwork(); // it cannot be found! } } } function notwork() { alert('I cant be executed when the request is complete!'); } All the js files has been added with a <script> tag (not shown for brevity). I think this is not the correct behaviour, I should have access to the document object like when I do the same from a regular <window>. Reproducible: Always Steps to Reproduce: 1. Follow what has been mentioned on details 2. Install the code so it can be executed from a chrome url 3. You will need a valid url for the dialog js code (it doesn't matter if it does not show a number, could be any web page, the point is make the onload function run) Actual Results: the javascript console shows errors about document not being declared, an exception when the alert() is called is shown first, that I think is telling me that there is no alert() declared or something. Expected Results: process the code as in a regular xul <window>
|parent| is a synonym for |self| in a non-frameset window. In other words, you are trying to find the tree in the current (dialog) window, not in the window where it exists. You probably want to use |opener| to refer back to the first window.
Status: UNCONFIRMED → RESOLVED
Closed: 23 years ago
Resolution: --- → INVALID
sorry my fault. please don't close this report since what you point out is more like a typo, I had to adapt my actual code into a small example and in the process I made the mistake, yes it's actually opener instead of parent but that not even probe why I have an error in the alert() calling in the first place. I think you have to give it a chance, if you can't please at least reasign this bug to someone who can take a look.
File an example that doesn't have any "typos" and that demonstrates the problem precisely, and reopen the bug. Also, be sure that what you are trying to do works for a generic HTML equivalent.
hehe Well this is the best I can do to make you see what I'm talking about. I've packaged two files, the main window is as you may guess main.xul, the other file is the dialog. All js code are into the xul files, the only thing you have to do is include the files in a chrome url you have already installed for development, and replace the url in main.xul that opens up the dialog. I have tested this code myself, so no typos will mislead your opinion. Its no-brainer and hope this time you can see the issue. I think an xpi file would be too much for this sole purpose. And remember I just want to help...
Status: RESOLVED → UNCONFIRMED
Resolution: INVALID → ---
Sure, thanks for the help. You have set up for an asynch load of the document. But you set that up in the ondialogaccept handler, which is going to immediately destroy the dialog (and calling context). So, the asynch callback falls on deaf ears; there is no |req.onload| function still alive to handle the event.
Status: UNCONFIRMED → RESOLVED
Closed: 23 years ago → 23 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: