Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 425
  • Last Modified:

Execute function inside iframe - FireFox problem

I have 2 files: index.html and iframe.html

index.html - has 3 links.
Click "create iframe" - dynamically creates iframe
Click "execute iframe" - executes function inside iframe ("Hello World")
Click "close iframe" - closes iframe

Problem in FireFox 1.5.0.2 - if I will repeat these steps again - will be error: "window.frames.iframe1.hello is not a function"

How to solve this problem?
-------------------------------------------
Most interesting:
I can click many times (in series) "create iframe" and after "execute iframe" - and it works!!!


****Below is code (index.html)****

<script>
   function createIframe() {
      document.getElementById('div').innerHTML='<iframe id="iframe1_id" name="iframe1" src="iframe.html" width="100" height="100"></iframe>';
   }
   function executeIframe() {
      //iframe1.hello();
      window.frames["iframe1"].hello();
   }
   function closeIframe() {
      document.getElementById('div').innerHTML='';
   }
</script>

<a href="#" onclick="createIframe();">create iframe</a>
<br>
<a href="#" onclick="executeIframe();">execute iframe</a>
<br>
<a href="#" onclick="closeIframe();">close iframe</a>

<div id="div"></div>




****Below is code (iframe.html)****
<script>
   function hello() {
alert("Hello World!");
   }
</script>
0
alexshop
Asked:
alexshop
1 Solution
 
RedKelvinCommented:
In executeIframe

reference the iframe using an integer, instead of the page name, looks like something gets cached badly, change
window.frames["iframe1"].hello();

to
frames[0].hello();

0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now