-2

Hi i want to call a function from 1 .html file to another .html file

Parent.html

<html>
<body>
<script>
function alertFunction() 
{
    alert("I am an alert box!");
}
</script>
<iframe src="childFile.html" width="80%" height="80%"></iframe>
</body>
</html>

Child.html

<button type="button" onClick="alertFunction()">button</button>

So when i hit the parent .html page a frame will open with the button in that frame......and when i click that button it should call that functiona and show the alert in parent.html file

sepp2k
  • 363,768
  • 54
  • 674
  • 675
taj
  • 19
  • 5

1 Answers1

0

onClick="parent.alertFunction()"

window.parent can do the job.

sincosmos
  • 370
  • 2
  • 7
  • 15
  • Uncaught SecurityError: Blocked a frame with origin "null" from accessing a frame with origin "null". Protocols, domains, and ports must match. for chrome i am getting this but other browser its working....how to resolve it – taj Oct 14 '14 at 07:31
  • I am sorry, I do not know much about Chrome. However, I searched it with google, it seems lots of programmers had encountered the same problem and they already found solutions. Please refer to http://stackoverflow.com/questions/17950598/using-iframe-with-local-files-in-chrome – sincosmos Oct 14 '14 at 07:43
  • @taj — Do your development with a local HTTP server instead of pointing the browser directly at your hard drive. – Quentin Oct 14 '14 at 13:55