0

私たちは、Web サイトの検索エンジン最適化に多くの時間を費やしてきました。モバイル ユーザーが検索エンジンのいずれかを使用している場合、通常の Web ページを反映したモバイル デザインの Web ページにモバイル ユーザーをリダイレクトしようとしています。サブフォルダー /mobile/ に設定されています。

メインの非モバイル ページでは、変数がキャプチャされます。

<% ThisPage = Request.ServerVariables("URL") %>
<% ThisVAR = "?" & Request.Querystring %>

これらの変数はインクルード ファイルにアクセスして、ユーザーがモバイル ユーザーかどうかを確認し、モバイル ユーザーが検索している可能性のあるページにリダイレクトします。ユーザーがモバイル デバイスを使用していて、検索しているページのモバイル バージョンがない場合は、モバイル フォルダー ルートにリダイレクトする必要があります。

<script type= "text/javascript">
if (screen.width <= 481)
{
    if (ThisPage = "/faqs.asp") { document.location = "../mobile/menu_faq.asp" }
    else {

    if (ThisPage = "/search.asp") { document.location = "../mobile/mobile_search.asp" }
else {

    if (ThisPage = "/mte_contacts.asp") { document.location = "../mobile/menu_contacts.asp" }
else {

    if (ThisPage = "/mte_history.asp") { document.location = "../mobile/menu_history.asp" }
    else {

    if (ThisPage = "/mte_locations.asp") { document.location = "../mobile/menu_locations.asp" }
else {

    if (ThisPage = "/mte_shipping.asp") { document.location = "../mobile/menu_shipping.asp" }
else {

    if (ThisPage = "/shop_discontinued.asp") { document.location = "../mobile/mobile_discontinued.asp" }
else {

    if (ThisPage = "/shop_category.asp") { document.location = "../mobile/mobile_category.asp" + ThisVAR }
else {

    if (ThisPage = "/shop_commodity.asp") { document.location = "../mobile/mobile_commodity.asp" + ThisVAR }

else { document.location = "../mobile/" }
}
}
}
}
}
}
}
}
}
</script>

私が抱えているjavascript if..elseの問題の解決策を探していましたが、コードにある構文エラーを修正するものが見つかりません。リダイレクトを機能させていますが、正しいモバイル ページに移動せず、正しいロジックを配置できません。どんな助けでも大歓迎です。現在、モバイル デバイスで /mnt_history.asp ファイルに移動することをテストしていますが、/mobile/menu_faq.asp にリダイレクトされます。

4

1 に答える 1

1

一連の if-else を使用するよりも、ルックアップ テーブルの方がおそらく優れた方法です。すべてのマッピングを 1 か所で確認する方がコンパクトで簡単です。

var mobileMapper = {
    "/faqs.asp"              : "../mobile/menu_faq.asp",
    "/search.asp"            : "../mobile/mobile_search.asp",
    "/mte_contacts.asp"      : "../mobile/menu_contacts.asp",
    "/mte_history.asp"       : "../mobile/menu_history.asp",
    "/mte_locations.asp"     : "../mobile/menu_locations.asp",
    "/mte_shipping.asp"      : "../mobile/menu_shipping.asp",
    "/shop_discontinued.asp" : "../mobile/mobile_discontinued.asp",
    "/shop_category.asp"     : "../mobile/mobile_category.asp" + ThisVAR ,
    "/shop_commodity.asp"    : "../mobile/mobile_commodity.asp" + ThisVAR 
};

if (screen.width <= 481) {
    document.location = mobilMapper[ThisPage] || "../mobile/";
}
于 2013-05-23T16:47:45.270 に答える