关于百度 site app,如何实现直接输入内容页面进行移动端的自动跳转?

在首页头部配置这个以后,直接访问网站首页是进行了移动端的跳转,但直接输入内容页面还是网页版的啊?怎么实现内容页面网址输入也是移动版的啊?

第1个回答  2015-04-24
在PC站点的head部分添加php函数,用于获取当前页面的移动地址:
<?php
/*-- 获取当前页面对应的移动页地址 --*/
function curMobURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://m.";$this_page = $_SERVER["REQUEST_URI"];
if (strpos($this_page, "?") !== false) $this_page = reset(explode("?", $this_page));
if ($_SERVER["SERVER_PORT"] != "80") {$pageURL .= $_SERVER["SERVER_NAME"] . ":" .$_SERVER["SERVER_PORT"] . $this_page;}
else {$pageURL .= $_SERVER["SERVER_NAME"] . $this_page;}
echo $pageURL;
}
?>

然后继续添加如下代码,则可在PC站所有页面的head中动态输出【移动适配\跳转】所需要的代码:
<script type="text/javascript">
(function(Switch){
var switch_pc = window.location.hash;
if(switch_pc != "#pc"){
if(/iphone|ipod|ipad|ipad|Android|nokia|blackberry|webos|webos|webmate|bada|lg|ucweb|skyfire|sony|ericsson|mot|samsung|sgh|lg|philips|panasonic|alcatel|lenovo|cldc|midp|wap|mobile/i.test(navigator.userAgent.toLowerCase())){
Switch.location.href='<?php curMobURL(); ?>';
}
}
})(window);
</script>
<meta name="mobile-agent" content="format=xhtml;url=<?php curMobURL(); ?>" />
<link href="<?php curMobURL(); ?>" rel="alternate" media="only screen and (max-width: 1000px)" />本回答被提问者和网友采纳
第2个回答  推荐于2016-04-07
在PC站点的head部分添加php函数,用于获取当前页面的移动地址:
<?php
/*-- 获取当前页面对应的移动页地址 --*/
function curMobURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://m.";$this_page = $_SERVER["REQUEST_URI"];
if (strpos($this_page, "?") !== false) $this_page = reset(explode("?", $this_page));
if ($_SERVER["SERVER_PORT"] != "80") {$pageURL .= $_SERVER["SERVER_NAME"] . ":" .$_SERVER["SERVER_PORT"] . $this_page;}
else {$pageURL .= $_SERVER["SERVER_NAME"] . $this_page;}
echo $pageURL;
}
?>

然后继续添加如下代码,则可在PC站所有页面的head中动态输出【移动适配\跳转】所需要的代码:
<script type="text/javascript">
(function(Switch){
var switch_pc = window.location.hash;
if(switch_pc != "#pc"){
if(/iphone|ipod|ipad|ipad|Android|nokia|blackberry|webos|webos|webmate|bada|lg|ucweb|skyfire|sony|ericsson|mot|samsung|sgh|lg|philips|panasonic|alcatel|lenovo|cldc|midp|wap|mobile/i.test(navigator.userAgent.toLowerCase())){
Switch.location.href='<?php curMobURL(); ?>';
}
}
})(window);
</script>
<meta name="mobile-agent" content="format=xhtml;url=<?php curMobURL(); ?>" />
<link href="<?php curMobURL(); ?>" rel="alternate" media="only screen and (max-width: 1000px)" />

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网