By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,503 Members | 1,188 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,503 IT Pros & Developers. It's quick & easy.

Calling a function from the iframe to the parent

100+
P: 132
Helo everybody,
I'm having a problem with a functioncall from my iFrame.

I have a page which houses an iframe. The contents of that is being generated in the script and has the following output:
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <script type='text/javascript'>
  4. function edt(idx)
  5. {
  6. alert(idx);
  7. parent.test();
  8. }
  9. </script>
  10. </head>
  11. <body>
  12. <table cellpadding='2' cellspacing='2' border='1'><tr><td>ID</td><td>date</td><td>client</td><td>program</td><td>start time</td><td>stop time</td><td>overtime</td><td>extra</td><td>cost</td><td>&nbsp;</td></tr><tr><td>0</td><td></td><td>none</td><td>test2</td><td>none</td><td>none</td><td>TBD</td><td></td><td>TBD</td><td><input type='button' value='EDIT' onclick='edt(0)'</td></tr>
  13. </table>
  14. </body>
  15. </html>
  16.  
I want to be able to edit the data by pushing the EDIT button which calls for the edt(index)-function. In that function as a way of testing I added an alert. Then I call on the test() function on the parent-page just again as a way of testing. That testfunction just displays an alertbox with Test in it.

So what happens when I push the button? Well I get the first alertbox with the indexnumber in it. So that's working well, but then when I try to call on the test function on the parent window I get "This property or method is not supported by this object". So clearly there is something wrong when he wants to access the functions on my parent page.

I've been looking all over the net and everywhere I keep finding the same answer parent.function() should do the trick except here it doesn't.

Might be worth mentioning that the functions are all in an external .js-file.

If anybody has the magic solution, please let me know :-)

Thanks!
Jun 16 '09 #1
Share this Question
Share on Google+
9 Replies


acoder
Expert Mod 15k+
P: 16,027
Can you show the code for the test() function?

Note that you haven't closed the input button properly.
Jun 16 '09 #2

100+
P: 132
@acoder
Expand|Select|Wrap|Line Numbers
  1. function test()
  2. {
  3. alert('Test');
  4. }
  5.  
@acoder
You're right, thanks for pointing that out.
Jun 16 '09 #3

acoder
Expert Mod 15k+
P: 16,027
Hmm, that should work. For good measure, I tested your code and it worked fine:
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4. function test()
  5. {
  6. alert('Test');
  7. }
  8. </script>
  9. </head>
  10. <body>
  11. Test<iframe src="iframetest.html">
  12. </body>
  13. </html>
Jun 16 '09 #4

100+
P: 132
@acoder
At first I thought the problem was due to the fact that I was generating the content of the iframe in the script rather than just loading a page. But I made a testpage to test everything and on that page it's doing it perfectly.

I copied and pasted it into my big page and there it fails again...

I'm going crazy on this one :-(
Jun 16 '09 #5

100+
P: 132
Aaahhhh,

Already one step closer...

What I didn't mention in my post is that my parent is actually an HTML Application and not an ordinary html-page.

So first of all I had to put the application="yes" inside my iframetags. But still it doesn't work...

So appearantly the hta doesn't work with parent.
Jun 16 '09 #6

100+
P: 132
@Cainnech
Strange but when I changed it in my big project then it works. So problem solved!
Me happy ;-)
Jun 16 '09 #7

acoder
Expert Mod 15k+
P: 16,027
Good for you! What exactly did you change?
Jun 16 '09 #8

100+
P: 132
I added the application="yes" to my iframe.

And I've should have know it because I used it before...
Jun 16 '09 #9

acoder
Expert Mod 15k+
P: 16,027
Simple once you know. Thanks for posting.
Jun 16 '09 #10

Post your reply

Sign in to post your reply or Sign up for a free account.