2014-08-28 62 views
0

我使用JSON(HTML源代碼),並且包含源的iframe像
如何在鏈接之前在iframe源代碼中添加http?

<iframe src="//www.youtube.com/embed/b34jsdg" height="360" width="640" allowfullscreen="" frameborder="0"></iframe><br> 

我無法www.youtube.com/embed/b34jsdg的鏈接,並使用此查詢之前添加HTTP。

<script>$('iframe').each(function(){var a = 'https://'+$(this).attr('src');$(this).attr('src',a);});</script> 

回答

0

確保在使用jQuery時,您正在等待文檔準備就緒,然後再更改它。

$(document).ready(function(e){ 
    // Your code here 
}); 

而且,只要一個鏈接來自於與「//」前綴服務器返回如你的iframe,那麼內容加載任何協議的頁面加載了過來。所以'//www.google.com'中的iframe加載從https:://somewebsite.com,該iframe將加載它的內容超過https也。因此iframe會加載https://www.google.com。