我正在研究一個應該在嵌入式視頻旁邊添加google +評論部分的wordpress插件。我可以使用javascript來初始獲取正確的寬度,但如果瀏覽器大小發生變化(參見圖像),自動加載到Iframe文檔中的腳本會自動將大小更改爲100%寬度。我在訪問Iframe下的文檔中的div時遇到嚴重困難,無法在調整大小時將其更改爲我想要的內容。google +評論和javascript
after adjusting the browser size it jumps below and goes to 100% width.
我使用thise代碼來生成評論部分:
<script src="https://apis.google.com/js/plusone.js"></script>
<div id="comments"></div>
<script>
gapi.comments.render('comments', {
href: [URL],
width: 'comments_w',
first_party_property: 'BLOGGER',
view_type: 'FILTERED_POSTMOD'
});
「comments_w」 是在計算的變量基於剩餘空間的早期JavaScript計算視頻的寬度後。
這是I幀被gnerated評價DIV
<iframe frameborder="0" hspace="0" marginheight="0" marginwidth="0" scrolling="no" style="position: static; top: 0px; width: 1138px; margin: 0px; border-style: none; left: 0px; visibility: visible; height: 616px;" tabindex="0" vspace="0" width="100%" id="I0_1480032087207" name="I0_1480032087207" src="https://apis.google.com/u/0/_/widget/render/comments?usegapi=1&href=http%3A%2F%2Fwww.cellcycle.net%2Ftemppage%2F&width=341&first_party_property=BLOGGER&view_type=FILTERED_POSTMOD&origin=http%3A%2F%2Fwww.cellcycle.net&search=&hash=&gsrc=3p&jsh=m%3B%2F_%2Fscs%2Fapps-static%2F_%2Fjs%2Fk%3Doz.gapi.en.CUXyo_wPfp0.O%2Fm%3D__features__%2Fam%3DAQ%2Frt%3Dj%2Fd%3D1%2Frs%3DAGLTcCMYqx5cA6SdMRKSM5YaRVPo-xpcPg#_methods=onPlusOne%2C_ready%2C_close%2C_open%2C_resizeMe%2C_renderstart%2Concircled%2Cdrefresh%2Cerefresh%2Cscroll%2Copenwindow&id=I0_1480032087207&parent=http%3A%2F%2Fwww.cellcycle.net&pfname=&rpctoken=30831408" data-gapiattached="true" title="Comment on this"></iframe>
#document == $0
<html est...>
</iframe>
內有控制寬度的體內一個div。我只需要找到一種方法來訪問它的JavaScript和改變大小,每當瀏覽器調整大小。我已經有了我希望在調整大小時調用的函數。我只是很難得到jQuery來找到文檔中的元素。
如果iframe的來源不同,則無法對其內容執行任何操作 –