帝國(guó)cms電腦pc站url跳轉(zhuǎn)到手機(jī)站url的方法
本文講解一下帝國(guó)cms電腦網(wǎng)站跳轉(zhuǎn)到手機(jī)動(dòng)態(tài)網(wǎng)站和手機(jī)靜態(tài)網(wǎng)站的方法。
方法一:帝國(guó)pc站跳轉(zhuǎn)到手機(jī)靜態(tài)站
1、假設(shè)我們有帝國(guó)cms 電腦網(wǎng)站www.XXX.com,手機(jī)網(wǎng)站m.XXX.com ,手機(jī)網(wǎng)站使用帝國(guó)cms的多訪問端功能制作,如果不了解帝國(guó)cms多訪問端制作手機(jī)網(wǎng)站的方法
現(xiàn)在電腦端和手機(jī)端都是生成靜態(tài)網(wǎng)站,除了域名不同,靜態(tài)連接地址都是相同的,例如:
www.XXX.com/china/1.html對(duì)應(yīng) m.XXX.com/china/1.html
2、接下來要給電腦網(wǎng)站的首頁、列表頁、內(nèi)容頁的模板添加跳轉(zhuǎn)代碼,方法如下:
js是瀏覽器跳轉(zhuǎn),meta是告訴搜索引擎移動(dòng)頁面的地址。
(1)首頁模板需添加下面代碼
| <script type="text/javascript"> try {var urlhash = window.location.hash;if (!urlhash.match("fromapp")) {if ((navigator.userAgent.match(/(iPhone|iPod|Android|ios|iPad)/i))) {window.location="http://m.XXX.com/";}}} catch(err) { }</script> <meta name="mobile-agent" content="format=xhtml;url=http://m.XXX.com/"> |
(2)封面頁和列表頁添加下面代碼
| <script type="text/javascript"> try {var urlhash = window.location.hash;if (!urlhash.match("fromapp")) {if ((navigator.userAgent.match(/(iPhone|iPod|Android|ios|iPad)/i))) {window.location="http://m.XXX.com<?=sys_ReturnBqClassUrl($class_r[$GLOBALS[navclassid]]);?>";}}} catch(err) { }</script> <meta name="mobile-agent" content="format=xhtml;url=http://m.XXX.com<?=sys_ReturnBqClassUrl($class_r[$GLOBALS[navclassid]]);?>"> |
(3)內(nèi)容頁添加下面代碼
| <script type="text/javascript"> try {var urlhash = window.location.hash;if (!urlhash.match("fromapp")) {if ((navigator.userAgent.match(/(iPhone|iPod|Android|ios|iPad)/i))) {window.location="http://m.XXX.com[!--titleurl--]";}}} catch(err) { }</script> <meta name="mobile-agent" content="format=xhtml;url=http://m.XXX.com[!--titleurl--]"> |
添加完上面代碼后,帝國(guó)cms的電腦網(wǎng)站的每個(gè)頁面都可以跳轉(zhuǎn)到手機(jī)靜態(tài)網(wǎng)站了。
但手機(jī)靜態(tài)站是有缺點(diǎn)的,每次我們更新電腦端文章,都要去手機(jī)端后臺(tái)重新生成一下html,比較麻煩,所以我們可以把手機(jī)站設(shè)置成動(dòng)態(tài)訪問,接下來就講解一下電腦端跳轉(zhuǎn)手機(jī)動(dòng)態(tài)站的方法。
方法二:帝國(guó)cms電腦網(wǎng)站跳轉(zhuǎn)到手機(jī)動(dòng)態(tài)站的方法
1、首先在電腦端的多訪問端設(shè)置,把手機(jī)端設(shè)置成強(qiáng)制動(dòng)態(tài)頁面模式。這樣手機(jī)站就是動(dòng)態(tài)了,不用每次都去生成html 。
2、接下來就是給電腦端模板的首頁、列表頁、內(nèi)容頁添加相依跳轉(zhuǎn)代碼,和方法一類似。
js是瀏覽器跳轉(zhuǎn),meta是告訴搜索引擎移動(dòng)頁面的地址。
(1)首頁模板需添加下面代碼
| <script type="text/javascript"> try {var urlhash = window.location.hash;if (!urlhash.match("fromapp")) {if ((navigator.userAgent.match(/(iPhone|iPod|Android|ios|iPad)/i))) {window.location="http://m.XXX.com/";}}} catch(err) { }</script> <meta name="mobile-agent" content="format=xhtml;url=http://m.XXX.com/"> |
(2)封面頁和列表頁添加下面代碼
| <script type="text/javascript"> try {var urlhash = window.location.hash;if (!urlhash.match("fromapp")) {if ((navigator.userAgent.match(/(iPhone|iPod|Android|ios|iPad)/i))) {window.location="http://m.XXX.com/e/action/ListInfo/?classid=[!--self.classid--]";}}} catch(err) { }</script> <meta name="mobile-agent" content="format=xhtml;url=http://m.XXX.com/e/action/ListInfo/?classid=[!--self.classid--]"> |
(3)內(nèi)容頁添加下面代碼
| <script type="text/javascript"> try {var urlhash = window.location.hash;if (!urlhash.match("fromapp")) {if ((navigator.userAgent.match(/(iPhone|iPod|Android|ios|iPad)/i))) {window.location="http://m.XXX.com/e/action/ShowInfo.php?classid=[!--classid--]&id=[!--id--]";}}} catch(err) { }</script> <meta name="mobile-agent" content="format=xhtml;url=http://m.XXX.com/e/action/ShowInfo.php?classid=[!--classid--]&id=[!--id--]"> |
添加上面代碼后,pc網(wǎng)站就可以跳轉(zhuǎn)到手機(jī)端的對(duì)應(yīng)網(wǎng)頁了。
注意:使用上面代碼時(shí),把代碼中的域名改成你自己的域名就可以了。
新聞熱點(diǎn)
疑難解答
圖片精選