[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

How do I get javascript passed through an iframe to call a method loaded from an ajax response?

Posted on 2009-04-10
4
Medium Priority
?
234 Views
Last Modified: 2013-11-19
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('6FB2A38DC107EACB');

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!
0
Comment
Question by:DSNews
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 2000 total points
ID: 24121767
you mean there is a script in the response you want to execute?
If you do, you need to eval it since dropping it into some div's innerHTML does not execute it.
Alternatively try to add the script to the DOM - there are quite a few examples on the net on
ondemand script dom
0
 

Author Comment

by:DSNews
ID: 24159426
With using mootools 1.2 Request.HTML can and will automatically eval your scripts.  The issue is that the scope of the first script with the function definition doesn't seem to be loaded in the same scope as the second script that loads in the ajax windo where the function call is placed.  The way I fixed it was to place the function def in the DOM, so it was global and accessible for all subsequential requests.  Thanks for the help!
0
 

Author Closing Comment

by:DSNews
ID: 31568997
Placing the function in the dom fixed the issue.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 24161459
Excellent.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question