DSNews
asked on
How do I get javascript passed through an iframe to call a method loaded from an ajax response?
Hey experts,
First off, let me say that my code uses the Mootools 1.2 framework, and I'm still pretty green with JS so this might be a simple thing to fix...
Pretty much, I have a profile page where users can edit their data by clicking a link in the section, and it populates the form into a div with AJAX via Request.HTML. Some of the forms are multiple pages, but they are all contained in that div. The issue I am having is on one of the pages, there is a photo upload part that makes use of AJAX and an iframe. The uploading part works fine in all browsers, but the javascript passed through the iframe on the response doesn't play well with IE(7 for sure) but FF is ok with it. Visual Studio debugs it as "Object doesn't support this property or method" while Google Chrome says "Object [object global] has no method 'setPhoto'". I'm thinking it has to do with the scope of it, and the fact that the js in the ajax was loaded after the dom was loaded. The code I am passing from the iframe is :
window.parent.setPhoto('6F B2A38DC107 EACB');
I've tried window.top.window.setPhoto () parent.setPhoto(), but I can't get any of them to access that method that is loaded in the ajax. Could someone please get me pointed in the right direction?
Thanks a bunch!
First off, let me say that my code uses the Mootools 1.2 framework, and I'm still pretty green with JS so this might be a simple thing to fix...
Pretty much, I have a profile page where users can edit their data by clicking a link in the section, and it populates the form into a div with AJAX via Request.HTML. Some of the forms are multiple pages, but they are all contained in that div. The issue I am having is on one of the pages, there is a photo upload part that makes use of AJAX and an iframe. The uploading part works fine in all browsers, but the javascript passed through the iframe on the response doesn't play well with IE(7 for sure) but FF is ok with it. Visual Studio debugs it as "Object doesn't support this property or method" while Google Chrome says "Object [object global] has no method 'setPhoto'". I'm thinking it has to do with the scope of it, and the fact that the js in the ajax was loaded after the dom was loaded. The code I am passing from the iframe is :
window.parent.setPhoto('6F
I've tried window.top.window.setPhoto
Thanks a bunch!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Placing the function in the dom fixed the issue.
Excellent.
ASKER