【问题标题】:(HTML) add a variable onto current URL(HTML) 在当前 URL 上添加一个变量
【发布时间】:2013-05-08 12:10:26
【问题描述】:

对您来说很容易,可以帮助非程序员。

我是一名帮助 Magento Go 店主的网页设计师。他们的网站以英语或德语显示。控制语言的小部件通过在当前 URL 上添加两个变量来进行更改:

?___store=default&___from_store=german (to change from German to English)
?___store=german&___from_store=default (to change from English to German)

我在页面顶部添加了两个 PNG 国家/地区标志,我希望单击这些标志中的任何一个以将上面的相应变量添加到当前 URL。

我该怎么做?

【问题讨论】:

    标签: html widget


    【解决方案1】:
    <a href="?___store=default&___from_store=german"><img src="german.png" /></a>
    

    <a href="javascript:window.location+='?___store=default&___from_store=german'"><img src="german.png" /></a>
    

    但这是一个 Magento 部署,商店切换器本身应该可以正常工作。

    【讨论】:

    • 简单。谢谢米海。 (店主出于某种原因想要这些旗帜)
    • 在 Magento 1.7 中有一个专门为标志定义的 store-switcher 模板。所以基本上您需要做的就是将添加商店切换器的布局 XML 从使用 language.phtmlstores.phtml 模板更改为使用此模板:app/design/frontend/base/default/template/page/switch/flags.phtml
    • 根据经验,您应该首先说明您的“最终目标”,记录您尝试过的内容,然后才提出一个可以解决您的“明显目标”的问题。通过绕过您的“明显目标”但仍然解决您的“最终目标”,某些解决方案可能会更好。
    【解决方案2】:

    使用 JavaScript:

    <img src = "yourgermanflagimg" onclick = "changeURL('german')" alt = "german flag">
    <img src = "yourenglishflagimg" onclick = "changeURL('english')" alt = "german flag">
    
    <script type = "text/javascript">
    function changeURL(type)
    {
    if(type=="german")
    {
    window.location.assign("www.yourpage.com?___store=default&___from_store=german");
    }
    else
    {
    window.location.assign("www.yourpage.com?___store=default&___from_store=default");
    }
    </script>
    

    【讨论】:

    • 解决方案应该将参数添加到当前 URL。如果您使用固定前缀(“yourpage.com”),则每次更改语言时都会被重定向到主页。
    • @MihaiStancu 我的印象是 OP 想用不同的语言重新加载他的当前页面。我加了前缀是因为我不知道他的页面的真实名称。
    • 这些 URL 是 Magento“商店”切换器的典型 URL。商店有相关的语言。因此,它(确实)是一个语言切换器。但它旨在将任何页面切换到其翻译版本。
    • @MihaiStancu 我明白了。对不起。我不知道如何在 JavaScript 中获取 URL,但我的答案仍然有效。
    猜你喜欢
    • 1970-01-01
    • 2015-01-27
    • 2015-05-06
    • 2016-08-01
    • 1970-01-01
    • 2011-03-10
    • 1970-01-01
    • 2017-08-25
    • 1970-01-01
    相关资源
    最近更新 更多