rldjrsksl / flex-iframe

Automatically exported from code.google.com/p/flex-iframe
0 stars 0 forks source link

callIFrameFunction() does not work with all ways to declare Javascript functions #69

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I am unable to get the callIFrameFunction method working. Below is my code 
snippet. Any help would be mich appreciated:-

I am calling a js function defined in my iframe source page:-

frame1.callIFrameFunction("clickMe");

In the html page, I have added the function:-

function clickMe()
{
alert('1'); 
}

But i dont get the alert. Please can anyone advice where I am going wrong.

Thanks

Original issue reported on code.google.com by niketkan...@gmail.com on 23 Feb 2010 at 7:01

GoogleCodeExporter commented 8 years ago

Original comment by Julien.N...@gmail.com on 14 May 2010 at 3:49

GoogleCodeExporter commented 8 years ago
Issue 3 has been merged into this issue.

Original comment by Julien.N...@gmail.com on 14 May 2010 at 4:33

GoogleCodeExporter commented 8 years ago
We need to fix this before upgrading to Flex 4.

Original comment by Julien.N...@gmail.com on 14 May 2010 at 5:04

GoogleCodeExporter commented 8 years ago
I have found that I have to define JavaScript functions that I want to call 
inside the iframe source page as 
attached specifically to the document object (as this is how the 
callIFrameFunction code expects to find them)

So for your example above, try changing the JS function to be declared like 
this:

document.clickMe = function ()
{
alert('1'); 
}

Original comment by ryan2...@gmail.com on 18 May 2010 at 3:05

GoogleCodeExporter commented 8 years ago
OK, I added an example for callIFrameFunction():
http://code.google.com/p/flex-
iframe/source/browse/#svn/trunk/examples/CallIFrameFunction

As Ryan said, you have to declare the function this way:

document.myFunction = function ()
{
    // ...
}

Original comment by Julien.N...@gmail.com on 19 May 2010 at 8:00

GoogleCodeExporter commented 8 years ago
I have copy the example and test it.

The parameter function doesn' work on IE8, but the other two works fine. 
On Firefox works but when the alert appears, Firefox freeze. 
Everything works fine on Chrome. 

anyone can help me to solve it?

Original comment by end...@gmail.com on 15 Oct 2010 at 11:50

GoogleCodeExporter commented 8 years ago
The problem is that you are trying to target the document while your methods 
are on the window object. Try this code instead:

public static var INSERT_FUNCTION_CALLIFRAMEFUNCTION:String = 
            "document.insertScript = function ()" +
            "{ " +
                "if (document." + FUNCTION_CALLIFRAMEFUNCTION + "==null)" +
                "{" +
                    FUNCTION_CALLIFRAMEFUNCTION + " = function (iframeID, functionName, args)" +
                    "{" +
                        "var iframeRef=document.getElementById(iframeID);" +
                        "var iframeWin;" +
                        "if (iframeRef.contentWindow) {" +
                            "iframeWin = iframeRef.contentWindow;" +
                        "} else if (iframeRef.contentDocument) {" +
                            "iframeWin = iframeRef.contentDocument.window;" +
                        "} else if (iframeRef.window) {" +
                            "iframeWin = iframeRef.windwo;" +
                        "}" +
                        "if (iframeWin.wrappedJSObject != undefined) {" +
                            "iframeWin = iframeDoc.wrappedJSObject;" +
                        "}" +
                        "return iframeWin[functionName](args);" +
                    "}" +
                "}" +
            "}";

Original comment by ernesto....@gmail.com on 13 Nov 2010 at 5:08

GoogleCodeExporter commented 8 years ago
Last post works like a charm. Thanks! Note that the proposed code has a typo, 
“iframeWin = iframeRef.windwo;”, should be “iframeWin = 
iframeRef.window;”.

Cheers,
Ivan

Original comment by ivan.str...@gmail.com on 8 Mar 2011 at 3:04

GoogleCodeExporter commented 8 years ago
Moved to https://github.com/nicoulaj/flex-iframe/issues/35

Original comment by Julien.N...@gmail.com on 8 May 2011 at 1:13

GoogleCodeExporter commented 8 years ago
Hello I'm new to these iFrame API. @Ivan mentioned that @ernesto's suggestion 
of using the INSERT_FUNCTION_CALLIFRAMEFUNCTION works like charm. I'm confused 
though how to use it. I assume the INSERT_FUNCTION_CALLIFRAMEFUNCTION is 
defined inside the Flex application, but how then do we invoke some javascript 
function using that, taking into consideration that different javascript method 
has different implementation or use ( Where do we insert the method 
body/implementation )?

Please kindly show how we can use the INSERT_FUNCTION_CALLIFRAMEFUNCTION. 

THANKS IN ADAVANCE.

Original comment by geniephu...@gmail.com on 8 May 2011 at 2:36

GoogleCodeExporter commented 8 years ago
As said earlier, project has been moved to 
https://github.com/nicoulaj/flex-iframe. This issue is fixed in version 1.5.

Original comment by Julien.N...@gmail.com on 15 May 2011 at 2:17