Anton Kozlovsky
Anton Kozlovsky

Reputation: 213

jquery search in iframe

i have smth like following code:

<html>
  <head>
  </head>
  <body>
     <button id="test1" onclick="OnSave()">Save</button>
  </body>
<script>
 function OnSave() {
  if ($("#test2").length)
    {
         alert("i see iframe");  
    }
  else
    {
       //some code that will call Iframe via ajax
    }
  }
</script>
</html>

When i click this button iframe have added:

<html>
      <head>
      </head>
      <body>
         <button id="test1" onclick="OnSave()">Save</button>
         <iframe id="test2" src="smth">//button inside that will fire OnSave event</iframe>
      </body>
    <script>
     function OnSave() {
      if ($("#test2").length)
        {
            alert("i see iframe");           
        }
      else
        {
          //some code that will call Iframe via ajax
        }
      }
    </script>
    </html>

So, when i click button that will call OnSave function from iframe,jquery didn't see my iframe or smth inside it.How should i call check if iframe exist?

Upvotes: 0

Views: 71

Answers (1)

Luca De Nardi
Luca De Nardi

Reputation: 2321

You're not calling the OnSave function like that.. try to do this instead

<button id="test1" onclick="OnSave()">Save</button>

(Note the parenthesis after the function name)

Edit: Ok, so you may want to get back to parent window before calling the function

window.parent.functionName();

Upvotes: 1

Related Questions