0

I have an iframe and inside that iframe a javascript function. I would like to be able to call that function from iframe's parent because I need to set some values inside the iframe when it opens. So far I tried:

 ClientScript.RegisterClientScriptBlock(this.GetType(), "saveTasks", "<script type='text/javascript'> function SaveTasks() { frames['myIframe'].location.href = 'myURL'; frames['myIframe'].test(); } </script>");

However, I am not able to call the test() function found in myURL file.

What is the specific syntax to do this, to call a javascript function inside child from its parent? Thank you

2
  • Is this iframe's URL in the same domain as your parent website? Commented Oct 18, 2012 at 16:31
  • Yes, it's in the same domain as the parent. Commented Oct 19, 2012 at 7:54

2 Answers 2

1

I'm not massively familiar with this. It doesn't appear though that this segment of javascript has any way of being able to know what "frames['myIframe']" is. There's a lot of things that could be potentially going wrong such as is the $document even loaded?

Sign up to request clarification or add additional context in comments.

Comments

0

Found the solution to this: it seems that my child page where the javascript function was found wasn't loaded at the moment when I was calling the function. Fortunately I found the solution to this here.

ClientScript.RegisterClientScriptBlock(this.GetType(), "saveTasks", "<script type='text/javascript'> function SaveTasks() { frames['ValidateTasksIframe'].location.href = 'myURL'; $('#ValidateTasksIframe').load(function() { frames['ValidateTasksIframe'].test();});} </script>"); 

Using event.load() works like a charm! :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.