J'ai une page qui a un iframe. Chaque fois que la page se charge, iframe reçoit un identifiant et un nom uniques. Je peux obtenir le nom de IFRAME iframe chargé comme ceci:Javascript: get iframe id dans la page chargée
alert(parent.window.frames[window.name].name);
Mais quand je tente d'obtenir l'identifiant:
alert(parent.window.frames[window.name].id);
-je obtenir undefined
?
Est-il possible d'obtenir l'attribut id de l'iframe dans la page chargée?
<iframe id="lyygi8stwZSANUEh" src="http://example.com" name="zma82vRVe18xbAqW" title="Awesome Iframe">
example.com:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Awesome Iframe</title>
</head>
<body>
<script type="text/javascript">
alert(parent.window.frames[window.name].name);
</script>
</body>
</html>
Voici un lien http://jsfiddle.net/cqFtB/ – Pav
qui précède donne l'erreur suivante: 'Permission denied accéder propriété « id '' – Pav
Cela peut arriver si l'iframe et la page qui le contient proviennent d'origines différentes. Sont-ils dans votre cas? –