0

I have 2 function one in iframe and another one out of iframe.

I want to call outer function from inner[iframe] function.

Can anyone help me?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Noor Khan
  • 528
  • 1
  • 5
  • 12

3 Answers3

1

You can use the parent attribute to go up in levels, and to the holder of the iframe to call its functions.

tvkanters
  • 3,519
  • 4
  • 29
  • 45
  • function foxbee() { obj = ''; val = document.getElementById(obj).value; if(window.parent.beagod()) { alert("okay"); parent.beagod(); } else { alert("never"); } //document.parent.beagod(val); } – Noor Khan Mar 31 '11 at 18:11
  • `function respondToComment(comment) { if(comment.contains(code) && !(comment.contains(question) || comment.contains(remark))) { alert('I\'m not sure what you're trying to say here.'); }` – tvkanters Mar 31 '11 at 18:14
  • `parent.functionName()` should do the trick. Are you certain that your JavaScript is being executed properly and that the function you're calling always returns `true`? – tvkanters Mar 31 '11 at 18:22
0

This is a good answered question about cross frame javascript function calling. Although the title mentions jQuery the answer is pure javascript

Community
  • 1
  • 1
Andre Pena
  • 56,650
  • 48
  • 196
  • 243
0

Answers relying on the parent object will only work if your iframes are hosted on the same domain. If going across domains, you'll need window.postMessage. The easyXDM library may provide the functionality you need in an easier to use (IE6/7 friendly) package, but I've never used it.

Mike Ruhlin
  • 3,546
  • 2
  • 21
  • 31