【发布时间】:2012-08-16 13:04:11
【问题描述】:
我在我网站的每个页面上都使用了它,如下所示,以避免在 Firefox 中查看网站时显示社交按钮:
<?php
if (!empty($_SERVER['HTTP_USER_AGENT']))
{
$isFirefox = (strpos($_SERVER['HTTP_USER_AGENT'],"Firefox") !== false);
} else {
$isFirefox = false;
}
if ($isFirefox) { echo ' '; }
else
include("/includes/social_buttons.php");?>
我的
social_buttons.php
包含以下代码:
<!--=================== social buttons ==================-->
<div id="social">
<!-- Google +1 button -->
<div style="float:right;padding-top:1px;">
<script type="text/javascript">document.write('<div class="g-plusone" data-size="tall"><\/div>');</script>
<script type="text/javascript">
(function() {
var z = document.createElement('script'), s = document.getElementsByTagName('script')[0];
z.type = 'text/javascript';
z.async = true;
z.src = 'https://apis.google.com/js/plusone.js';
s.parentNode.insertBefore(z, s);
})();
</script>
</div>
<!-- End Google +1 button -->
<!-- Facebook button -->
<div style="float:right;padding-right:2px;">
<script type="text/javascript">
//<![CDATA[
document.write('<div id="fb-root"><\/div><fb:like href="<?php echo $url;?>" send="false" layout="box_count" width="35" show_faces="false" font="arial"><\/fb:like>');
(function() {
var s = document.createElement('SCRIPT'), s1 = document.getElementsByTagName('SCRIPT')[0];
s.type = 'text/javascript';
s.async = true;
s.src = 'http://connect.facebook.net/en_US/all.js#xfbml=1';
s1.parentNode.insertBefore(s, s1);
})();
//]]>
</script>
</div>
<!-- End Facebook button -->
<!-- Tweet Button -->
<div style="float:right; margin-right:11px;">
<a href="http://twitter.com/share?via=youraccount&count=vertical" class="twitter-share-button">Tweet</a>
<script type="text/javascript">
var a = document.createElement('script'), b = document.getElementsByTagName('script')[0];
a.type = 'text/javascript';
a.async = true;
a.src = 'http://platform.twitter.com/widgets.js';
b.parentNode.insertBefore(a,b);
</script>
</div>
<!-- End Tweet Button -->
<!-- end #social --></div>
<!--=================== end.social buttons ==================-->
现在的问题是,我想在我的 social_buttons.php 中添加一些额外的内容,这些内容将显示在包括 firefox 在内的每个浏览器中。
所以我的尝试(这没有奏效!)是把它全部放在我的 social_buttons.php 中,然后用更简单的包含调用来调用它
<?php include("/includes/social_buttons.php");?>
因此 social_buttons.php 的内容看起来像这样:
<?php if (!empty($_SERVER['HTTP_USER_AGENT']))
{
$isFirefox = (strpos($_SERVER['HTTP_USER_AGENT'],"Firefox") !== false);
} else {
$isFirefox = false;
}
if ($isFirefox) { echo ' '; }
else
echo ("
<!--=================== social buttons ==================-->
<div id="social">
<!-- Google +1 button -->
<div style="float:right;padding-top:1px;">
<script type="text/javascript">document.write('<div class="g-plusone" data-size="tall"><\/div>');</script>
<script type="text/javascript">
(function() {
var z = document.createElement('script'), s = document.getElementsByTagName('script')[0];
z.type = 'text/javascript';
z.async = true;
z.src = 'https://apis.google.com/js/plusone.js';
s.parentNode.insertBefore(z, s);
})();
</script>
</div>
<!-- End Google +1 button -->
<!-- Facebook button -->
<div style="float:right;padding-right:2px;">
<script type="text/javascript">
//<![CDATA[
document.write('<div id="fb-root"><\/div><fb:like href="<?php echo $url;?>" send="false" layout="box_count" width="35" show_faces="false" font="arial"><\/fb:like>');
(function() {
var s = document.createElement('SCRIPT'), s1 = document.getElementsByTagName('SCRIPT')[0];
s.type = 'text/javascript';
s.async = true;
s.src = 'http://connect.facebook.net/en_US/all.js#xfbml=1';
s1.parentNode.insertBefore(s, s1);
})();
//]]>
</script>
</div>
<!-- End Facebook button -->
<!-- Tweet Button -->
<div style="float:right; margin-right:11px;">
<a href="http://twitter.com/share?via=youraccount&count=vertical" class="twitter-share-button">Tweet</a>
<script type="text/javascript">
var a = document.createElement('script'), b = document.getElementsByTagName('script')[0];
a.type = 'text/javascript';
a.async = true;
a.src = 'http://platform.twitter.com/widgets.js';
b.parentNode.insertBefore(a,b);
</script>
</div>
<!-- End Tweet Button -->
<!-- end #social --></div>
<!--=================== end.social buttons ==================-->
");?>
SOME OTHER CODE I WANT TO INCLUDE
有什么办法吗?
【问题讨论】:
-
究竟是什么没用?是问题所在:它们不显示或不工作?
-
只需对 social_buttons.php 进行
is_firefox测试,并使用它来确定显示的内容。这里有什么问题? -
您还应该确保您的嵌套引号被转义。
-
你严重搞砸了你的代码。有很多语法错误。你混淆了
'和",你的echo里面有<?php echo $url;?>。您需要先清理代码。您不能将所有内容都包含在echo语句中。
标签: php javascript html server-side-includes