0
我使用iFrame加載http://www.amazon.co.uk當我按下亞馬遜英國按鈕,它也加載以及我瀏覽amazon.co.uk的子頁面。現在我想要的是當我懸停在此iFrame中的標籤或鏈接上時獲取標籤的href屬性。 使用Javascript或jQuery有可能請告訴我如何?在iFrame中訪問動態生成的元素
- 這是我在做什麼
<div id="amazon_buttons">
<table border="0">
<tr>
<td><a href="../../users/product" target="_top"><input id="cmdback" name="cmdback" type="button" value="Back To IEC" /></a></td>
</tr>
<tr>
<td><input id="cmdanzuk" name="cmdanzuk" type="button" value="Amazon UK" onclick="open_amazon_page('uk')" /> </td>
</tr>
<tr>
<td><input id="cmdanzde" name="cmdanzde" type="button" value="Amazon DE" onclick="open_amazon_page('de')" /> </td>
</tr>
<tr>
<td><input id="cmdanzfr" name="cmdanzfr" type="button" value="Amazon FR" onclick="open_amazon_page('fr')" /> </td>
</tr>
<tr>
<td><input id="cmdanzes" name="cmdanzes" type="button" value="Amazon ES" onclick="open_amazon_page('es')" /> </td>
</tr>
</table>
</div>
<iframe id="azn_iframe" name="azn_iframe" src="" style="clear: both; width: 100%; height:800px;"></iframe>
$("#azn_iframe").contents().find("a").hover( function() { alert($(this).attr("href")); }); function open_amazon_page($platform) { if($platform == 'uk') azn_iframe.location.href = "http://www.amazon.co.uk"; else if($platform == 'de') azn_iframe.location.href = "http://www.amazon.de"; else if($platform == 'fr') azn_iframe.location.href = "http://www.amazon.fr"; else if($platform == 'es') azn_iframe.location.href = "http://www.amazon.es"; } </script>
http://en.wikipedia.org/wiki/Same_origin_policy – jbabey 2012-07-11 13:02:47