Access-Control-Allow-Origin ne fonctionne pas pour iframe avec le même domaine

J'essaye d'accéder à un iframe dans un sous-domaine et obtenez une croix erreur de domaine.

Voici le code de exemple.mydomain.com/iframe_test.html:

<html>
<head>
     <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
</head>
<body>
    <iframe src="http://example2.mydomain.com/welcome.php" width="1000" height="600"></iframe>
    <script>
        $(document).ready(function()
        {
            setTimeout(function(){
                $('#innerdiv',$('iframe').contents()).hide();
            },5000);
        });
    </script>
</body>
</html>

Et voici le code de exemple2.mydomain.com/welcome.php:

<?php
header("Access-Control-Allow-Origin: " . "*");
?>
<html>
<head>

</head>
<body>
    <div id="innerdiv">
        hello
    </div>
</body>
</html>

Lorsque la ligne $('#innerdiv',$('iframe').contenu()).hide() est exécutée, l'erreur suivante se produit:

Uncaught SecurityError: Failed to read the 'contentDocument' property from 'HTMLIFrameElement': Blocked a frame with origin "http://example.mydomain.com" from accessing a frame with origin "http://example2.mydomain.com". Protocols, domains, and ports must match. 

J'ai vérifié avec un violon que l'Access-Control-Allow-Origin-tête était vraiment retourné dans la réponse de welcome.php

Est-il possible d'accéder au contenu d'une iframe dans un sous-domaine?

source d'informationauteur Edi | 2014-04-29