对网页分享技术的思考

        提高网页浏览量是提高网站信息影响的前提,提高网页浏览量的方式是多种多样的,其中向特定页面添加网页分享是一个很好的主意,网页分享实现方式很多,这里介绍一下百度分享的应用:

        一、百度分享相关网址:

        获取代码:http://share.baidu.com/code

        帮助文档:http://share.baidu.com/help

        二、百度分享之图标式:

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath()+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<title>图标式</title>
	</head>
  
	<body>
		<!-- Baidu Button BEGIN -->
			<div id="bdshare" class="bdshare_t bds_tools get-codes-bdshare">
		        <a class="bds_qzone"></a>
		        <a class="bds_tsina"></a>
		        <a class="bds_tqq"></a>
		        <a class="bds_renren"></a>
		        <span class="bds_more">更多</span>
			</div>
			<script type="text/javascript" id="bdshare_js" data="type=tools&mini=1" ></script> 
			<script type="text/javascript" id="bdshell_js"></script> 
			<script type="text/javascript">
				var bds_config = {
					'bdText':'分享内容',
					'bdComment':'分享评论',
					'bdPic':'http://avatar.csdn.net/E/A/D/1_wangshuxuncom.jpg'
				};
				document.getElementById('bdshell_js').src = "http://bdimg.share.baidu.com/static/js/shell_v2.js?cdnversion=" + Math.ceil(new Date()/3600000);
			</script>
		<!-- Baidu Button END -->
	</body>
</html>

        三、百度分享之文字式:

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath()+"/";
    String skinId = request.getParameter("skinId");
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<title>文字式</title>
		<style type="text/css">
			a{
				text-decoration: none;
			}
		</style>
	</head>
  
	<body>
		<div class="bdsharebuttonbox">
			<a href="#" class="bds_more" data-cmd="more">分享到:</a>
			<a href="#" class="bds_qzone" data-cmd="qzone" title="分享到QQ空间">QQ空间</a>
			<a href="#" class="bds_tsina" data-cmd="tsina" title="分享到新浪微博">新浪微博</a>
			<a href="#" class="bds_tqq" data-cmd="tqq" title="分享到腾讯微博">腾讯微博</a>
			<a href="#" class="bds_renren" data-cmd="renren" title="分享到人人网">人人网</a>
			<a href="#" class="bds_weixin" data-cmd="weixin" title="分享到微信">微信</a>
		</div>
		<script type="text/javascript">
			window._bd_share_config={
				"common":{"bdText":"分享内容","bdComment":"分享评论","bdMini":"2","bdMiniList":false,"bdPic":"http://avatar.csdn.net/E/A/D/1_wangshuxuncom.jpg","bdStyle":"0","bdSize":"16"},
				"share":{"bdSize":16},
				"image":{"viewList":["qzone","tsina","tqq","renren","weixin"],"viewText":"分享到:","viewSize":"16"},
				"selectShare":{"bdContainerClass":"bdsharebuttonbox","bdSelectMiniList":["qzone","tsina","tqq","renren","weixin"]}
			};
			with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];
			</script>
	</body>
</html>

        三、百度分享之浮窗式

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath()+"/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
	<head>
		<title>浮窗式</title>
		<script type="text/javascript">
			window._bd_share_config={
				"common":{"bdText":"分享内容","bdComment":"分享评论","bdMini":"2","bdMiniList":false,"bdPic":"http://avatar.csdn.net/E/A/D/1_wangshuxuncom.jpg","bdStyle":"0","bdSize":"16"},
				"slide":{"type":"slide","bdImg":"6","bdPos":"right","bdTop":"250"},
				"image":{"viewList":["qzone","tsina","tqq","renren","weixin"],"viewText":"分享到:","viewSize":"16"},
				"selectShare":{"bdContainerClass":null,"bdSelectMiniList":["qzone","tsina","tqq","renren","weixin"]}
			};
			with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];
		</script>
	</head>
  	
	<body>
	
	</body>
</html>

        五、遇到的问题及其解决方法:

        ①、我的工程名为shareDemo,项目通过Tomcat发布,http输入http://localhost:8080/share/index.html,然后选择并点击“分享到QQ空间”,可是出来的界面不能显示分享内容(如下图),但是其它分享好用:


图片4-1-1

        解决方法:这种问题并不是你的代码写错了,而是QQ做了限制——如果http请求中为localhost,那么是不会返回结果的,可以通过将localhost改为计算机IP地址或者改为127.0.0.1解决这个问题。

        ②、使用浮窗式百度分享时,用IE打开相应的页面,没有发现所谓的“浮窗”啊,其它浏览器(譬如火狐、谷歌或者Safari)都好用?

        解决方法:嗯嗯嗯,这个问题我也曾经遇到过,几经研究发现是页面文档类型搞的鬼——研究发现如果为“<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">”,则在IE或者360浏览器中浮窗式的百度分享会不好用——显示不出来;如果为“<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">”则在IE或者360浏览器中浮窗式的百度分享会比较好的显示出来;

        补充性说明:上面列出的三个例子是最简单的例子,要弄清每个参数什么意思以及其它的一些配置,请访问官方网站。

       【0分下载资源

对网页分享技术的思考,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。