Jump to the corresponding mobile page when accessing the Pc-side Web page on the mobile side
Source: Internet
Author: User
<span id="Label3"></p><p><p>Do not want to through the CSS self-adaptation in the PC side and mobile display of different styles, then only through the mobile access to the Pc-side Web page to jump to the corresponding mobile page, then how to jump, there are many articles on the internet, the following is my test effective way.</p></p><p><p>1.</p></p><p><p>Pc-side Access Display:</p></p><p><p></p></p><p><p>Mobile-side Access Display:</p></p><p><p></p></p><p><p></p></p><p><p>2. achieve:</p></p><p><p>Do not consider the mobile search engine optimization, only need to determine whether the mobile side by js, and then determine whether to jump to the specified page on the line, the main JS as Follows:</p></p><pre><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">determines whether the mobile side, if yes, jumps to the specified URL address</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">function</span></span><span style="color: #000000;"><span style="color: #000000;">browserredirect (url) {</span></span><span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;">a <span style="color: #008000;">Read-only String that declares the value of the user agent header used by the browser for HTTP requests</span></span> <span style="color: #0000ff;"><span style="color: #0000ff;">var</span></span>Suseragent =<span style="color: #000000;"><span style="color: #000000;">Navigator.userAgent.toLowerCase (); </span></span><span style="color: #0000ff;"><span style="color: #0000ff;">var</span></span>Bisiphoneos = Suseragent.match (/iphone Os/i) = = "iphone os"<span style="color: #000000;"><span style="color: #000000;">; </span></span><span style="color: #0000ff;"><span style="color: #0000ff;">var</span></span>BISMIDP = Suseragent.match (/midp/i) = = "midp"<span style="color: #000000;"><span style="color: #000000;">; </span></span><span style="color: #0000ff;"><span style="color: #0000ff;">var</span></span>BIsUc7 = Suseragent.match (/rv:1.2.3.4/i) = = "rv:1.2.3.4"<span style="color: #000000;"><span style="color: #000000;">; </span></span><span style="color: #0000ff;"><span style="color: #0000ff;">var</span></span>BISUC = Suseragent.match (/ucweb/i) = = "ucweb"<span style="color: #000000;"><span style="color: #000000;">; </span></span><span style="color: #0000ff;"><span style="color: #0000ff;">var</span></span>Bisandroid = Suseragent.match (/android/i) = = "android"<span style="color: #000000;"><span style="color: #000000;">; </span></span><span style="color: #0000ff;"><span style="color: #0000ff;">var</span></span>Bisce = Suseragent.match (/windows Ce/i) = = "windows ce"<span style="color: #000000;"><span style="color: #000000;">; </span></span><span style="color: #0000ff;"><span style="color: #0000ff;">var</span></span>BISWM = Suseragent.match (/windows Mobile/i) = = "windows mobile"<span style="color: #000000;"><span style="color: #000000;">; </span></span><span style="color: #0000ff;"><span style="color: #0000ff;">if</span></span>(bisiphoneos | | bismidp | | bIsUc7 | | bisuc | | bisandroid | | bisce | |<span style="color: #000000;"><span style="color: #000000;">Biswm) {window.location.replace (url); }}</span></span></pre><p><p>Then in the page reference js, call the method on the Line:</p></p><pre> <span style="color: #0000ff;"><span style="color: #0000ff;"><</span></span><span style="color: #800000;"><span style="color: #800000;">Script</span></span><span style="color: #ff0000;"><span style="color: #ff0000;">src</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">=".. /js/wap.js "</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">></</span></span><span style="color: #800000;"><span style="color: #800000;">Script</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">></span></span> <span style="color: #0000ff;"><span style="color: #0000ff;"><</span></span><span style="color: #800000;"><span style="color: #800000;">Script</span></span><span style="color: #ff0000;"><span style="color: #ff0000;">type</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">= "text/javascript"</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">></span></span><span style="background-color: #f5f5f5; color: #000000;"><span style="background-color: #f5f5f5; color: #000000;">Browserredirect (</span></span><span style="background-color: #f5f5f5; color: #000000;"><span style="background-color: #f5f5f5; color: #000000;">"</span></span><span style="background-color: #f5f5f5; color: #000000;"><span style="background-color: #f5f5f5; color: #000000;">http://ycdoit.com/test/testmobile.html</span></span><span style="background-color: #f5f5f5; color: #000000;"><span style="background-color: #f5f5f5; color: #000000;">"</span></span><span style="background-color: #f5f5f5; color: #000000;"><span style="background-color: #f5f5f5; color: #000000;">);</span></span><span style="color: #0000ff;"><span style="color: #0000ff;"></</span></span><span style="color: #800000;"><span style="color: #800000;">Script</span></span><span style="color: #0000ff;"><span style="color: #0000ff;">></span></span></pre><p><p></p></p><p><p>PS: You can use the Pc-side and mobile-side access to <span style="color: #0000ff;">test pages</span> to see the Effect.</p></p><p><p>Jump to the corresponding mobile page when accessing the Pc-side Web page on the mobile side</p></p></span>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service