0

I have a .asp page that loads some frames and I need to access their content.

I tried to use jquery .contents() method by replicating the official example from the documentation but even that doesn't work.

Here's my code snippets

HOME.HTML

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>contents demo</title>
  <script src="jquery-1.12.4.js"></script>
</head>
<body>

<iframe src="mycom.html" width="80%" height="600" id="frameDemo"></iframe>

<script>
$( "#frameDemo" ).contents().find( "div" ).css( "background-color", "#BADA55" );
</script>

</body>
</html>

MYCOM.HTML

<!DOCTYPE html>
<html>
<head>
<title></title>
</head>

<body>
    <div id="foo"><H1>MYCOM FRAME!</H1></div>
</body>

</html>

Also using .load on the frame to ensure that its content is fully loaded does not work.

What am I doing wrong?

Rob
  • 26,989
  • 16
  • 82
  • 98
Flavio
  • 1
  • edit: iframe example works using .load method with jquery. But why i've no lock using frameset and frames with the same code? – Flavio Aug 22 '16 at 11:24

1 Answers1

0

Here is the solution to your question.

jQuery/JavaScript: accessing contents of an iframe

Your code is OK, but you can't access iframes from a different domain as your page.

Community
  • 1
  • 1