[英]I want to change the width of element inside an Iframe
我在單個帖子的左側使用了社交側邊欄。 我想以相同大小顯示所有按鈕,但現在它們以不同大小顯示。 我要使它們的大小都相同,例如“ twitter”按鈕。 如需檢查,請到這里 。
我嘗試了許多代碼,但由於它們的來源是Iframe,所以我的編碼無法正常工作。 對於google +,我使用了以下代碼:
$('#___plusone_1 iframe').load(function(){
$('#___plusone_1 iframe').contents().addClass('googleplusbtn');
}
那你能幫我嗎? 謝謝。
我也檢查了這些教程,但對我不起作用:
我認為您無法實現此目標,因為您的主頁( http://site4preview.site90.net/ )和iframe( http://www.facebook.com/plugins/like.php )位於不同的域中。
jQuery Contents功能描述:
如果iframe與主頁位於同一域中,則.contents()方法還可用於獲取iframe的內容文檔。
資料來源: JQuery .contents()
如果iframe網址來自同一域。 然后,您可以使用:
jQuery的:
$("#iFrame").contents().find(".someButtons").addClass("googleplusbtn");
如果iframe包含相同應用程序域的頁面,則可以通過以下方式實現:
var iframe = document.getElementById('html2');
var innerDoc = iframe.contentDocument || iframe.contentWindow.document;
一旦獲得對象,現在就可以訪問:
innerDoc.getElementById('divId').style.width="250px";
您可以使用jQuery輕松更改iFrame的寬度。此解決方案與iFrame相同。 我創建了一個PHP腳本,可以從其他網站獲取所有內容,而最重要的部分是您可以輕松地將自定義jQuery應用於該外部內容。 請參考以下腳本,該腳本可以從其他網站獲取所有內容,然后您也可以應用自定義jQuery / JS。 此內容可以在任何元素或任何頁面內的任何位置使用。
<div id='myframe'>
<?php
/*
Use below function to display final HTML inside this div
*/
//Display Frame
echo displayFrame();
?>
</div>
<?php
/*
Function to display frame from another domain
*/
function displayFrame()
{
$webUrl = 'http://[external-web-domain.com]/';
//Get HTML from the URL
$content = file_get_contents($webUrl);
//Add custom JS to returned HTML content
$customJS = "
<script>
/* Here I am writing a sample jQuery to hide the navigation menu
You can write your own jQuery for this content
*/
//Hide Navigation bar
jQuery(\".navbar.navbar-default\").hide();
</script>";
//Append Custom JS with HTML
$html = $content . $customJS;
//Return customized HTML
return $html;
}
您可以使用jQuery輕松更改寬度。 此解決方案與iFrame相同。 我創建了一個PHP腳本,可以從其他網站獲取所有內容,而最重要的部分是您可以輕松地將自定義jQuery應用於該外部內容。 請參考以下腳本,該腳本可以從其他網站獲取所有內容,然后您也可以應用自定義jQuery / JS。 此內容可以在任何元素或任何頁面內的任何位置使用。
<div id='myframe'>
<?php
/*
Use below function to display final HTML inside this div
*/
//Display Frame
echo displayFrame();
?>
</div>
<?php
/*
Function to display frame from another domain
*/
function displayFrame()
{
$webUrl = 'http://[external-web-domain.com]/';
//Get HTML from the URL
$content = file_get_contents($webUrl);
//Add custom JS to returned HTML content
$customJS = "
<script>
/* Here I am writing a sample jQuery to hide the navigation menu
You can write your own jQuery for this content
*/
//Hide Navigation bar
jQuery(\".navbar.navbar-default\").hide();
</script>";
//Append Custom JS with HTML
$html = $content . $customJS;
//Return customized HTML
return $html;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.