[英]I want to change the width of element inside an Iframe
I used a social sidebar in the left side of single post. 我在单个帖子的左侧使用了社交侧边栏。 I want to show all the buttons in the same sizes, they are now showing in different sizes. 我想以相同大小显示所有按钮,但现在它们以不同大小显示。 I want to make them all the same sizes like the "twitter" button. 我要使它们的大小都相同,例如“ twitter”按钮。 For checking please go here . 如需检查,请到这里 。
I tried many code but as their source is Iframe that's why my coding is not working. 我尝试了许多代码,但由于它们的来源是Iframe,所以我的编码无法正常工作。 For google+ I used the following code: 对于google +,我使用了以下代码:
$('#___plusone_1 iframe').load(function(){
$('#___plusone_1 iframe').contents().addClass('googleplusbtn');
}
So can you please help me ? 那你能帮我吗? Thanks. 谢谢。
I have checked these tutorials also but don't work for me: 我也检查了这些教程,但对我不起作用:
jQuery changing contents of an iFrame jQuery更改iFrame的内容
jQuery/JavaScript: accessing contents of an iframe jQuery / JavaScript:访问iframe的内容
I don't think you can achieve this as your main page ( http://site4preview.site90.net/ ) and the iframes ( http://www.facebook.com/plugins/like.php ) are in different domains. 我认为您无法实现此目标,因为您的主页( http://site4preview.site90.net/ )和iframe( http://www.facebook.com/plugins/like.php )位于不同的域中。
Jquery Contents function description: jQuery Contents功能描述:
The .contents() method can also be used to get the content document of an iframe, if the iframe is on the same domain as the main page. 如果iframe与主页位于同一域中,则.contents()方法还可用于获取iframe的内容文档。
Source: JQuery .contents() 资料来源: JQuery .contents()
If iframe url are from same domain. 如果iframe网址来自同一域。 Then you can use: 然后,您可以使用:
Jquery: jQuery的:
$("#iFrame").contents().find(".someButtons").addClass("googleplusbtn");
if Iframe contain page of same application domain then it is possible, by: 如果iframe包含相同应用程序域的页面,则可以通过以下方式实现:
var iframe = document.getElementById('html2');
var innerDoc = iframe.contentDocument || iframe.contentWindow.document;
once you get the object, now you can access: 一旦获得对象,现在就可以访问:
innerDoc.getElementById('divId').style.width="250px";
Here you go, you can easily change the width of iFrame using jQuery.This solution works same as iFrame. 您可以使用jQuery轻松更改iFrame的宽度。此解决方案与iFrame相同。 I have created a PHP script that can get all the contents from the other website, and most important part is you can easily apply your custom jQuery to that external content. 我创建了一个PHP脚本,可以从其他网站获取所有内容,而最重要的部分是您可以轻松地将自定义jQuery应用于该外部内容。 Please refer to the following script that can get all the contents from the other website and then you can apply your cusom jQuery/JS as well. 请参考以下脚本,该脚本可以从其他网站获取所有内容,然后您也可以应用自定义jQuery / JS。 This content can be used anywhere, inside any element or any page. 此内容可以在任何元素或任何页面内的任何位置使用。
<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;
}
You can easily change the width using jQuery. 您可以使用jQuery轻松更改宽度。 This solution works same as iFrame. 此解决方案与iFrame相同。 I have created a PHP script that can get all the contents from the other website, and most important part is you can easily apply your custom jQuery to that external content. 我创建了一个PHP脚本,可以从其他网站获取所有内容,而最重要的部分是您可以轻松地将自定义jQuery应用于该外部内容。 Please refer to the following script that can get all the contents from the other website and then you can apply your cusom jQuery/JS as well. 请参考以下脚本,该脚本可以从其他网站获取所有内容,然后您也可以应用自定义jQuery / JS。 This content can be used anywhere, inside any element or any page. 此内容可以在任何元素或任何页面内的任何位置使用。
<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.