替换部分URL onclick和重定向

我试图在这里和谷歌上寻找答案,但也许我没有使用正确的搜索词。 ..我找不到它。
希望有人能帮助我。</ p>

双语</ code>商店我想要一个人被重定向 单击 english flag </ code>按钮时,在不同的 domain / url </ code>上显示相同的产品。</ p>

www.mydomain * * .nl / a1 ** / product1.html </ code> </ p>

是起点。 单击英文标记应该抓取域和类别并更改它并转到新创建的URL:</ p>

www.mydomain **。com / a2 ** / product1。 HTML </代码> </ p>

然后</ p>

<代码> www.mydomain **。NL / B1 ** / product1.html </代码> ,点击“英国国旗”按钮后变为:</ p>

www.mydomain **。com / b2 ** / product1.html </ code> </ p>

等。</ p>

大约有30个不同的页面要像这样被删除,所有页面都有相同的“英国国旗”按钮。</ p>

如果url的一部分是'.nl / schoenen /'然后更改并转到'.com / shoes /'</ p>

如果网址的一部分是'.nl / jassen /'那么更改 并转到'.com / jackets /'</ p>
</ div>

展开原文

原文

I have tried to look for answers here and on google, but maybe I'm not using the correct search terms... I just can't find it. Hope anyone can help me with this.

On a bi-lingual shop I want a person to be redirected to the same product on a different domain/url, when clicking the english flag button.

www.mydomain**.nl/a1**/product1.html

is the starting point. Clicking on the english flag should grab the domain and category and change this and go to the newly created url:

www.mydomain**.com/a2**/product1.html

then

www.mydomain**.nl/b1**/product1.html ,becomes after clicking the 'english flag' button:

www.mydomain**.com/b2**/product1.html

etc.

There are about 30 different pages to be redicted like this, all with the same 'english flag' button.

IF part of url is '.nl/schoenen/' THEN change and go to '.com/shoes/'

IF part of url is '.nl/jassen/' THEN change and go to '.com/jackets/'

4个回答



TL; DR </ strong> - 使用一些javascript来操作网址onclick,按照您希望的方式重新组合网址, 重新加载新网址。</ p>

我做了一次双语商店,并在路径中插入了'es'或'en'来表示西班牙语或英语,基本上是作为URL参数。 你的目标有点复杂(我认为必须如此),但这可能会让你开始。 你可以看到在这里购物 (不是我的设计 - 不要怪我。很多都是 根据所有者的要求离线(一些合法的东西),但您应该能够导航某些页面并查看有效的语言切换。)</ em> </ p>

单击语言切换会触发一些简单的操作 Javascript如下:</ p>

  function switchLanguage(lang){
u = location.href.split('/');
u [3] = lang;
location。 href = u.join('/');
}
</ code> </ pre>

然后将 onclick </ code>添加到语言切换链接到 direct onclick =“switchLanguage('en')”</ code>或 onclick =“switchLanguage('es')”</ code>,或者你注入的URL是什么。 同样,这是特定于我的示例,其中URL参数将遵循第三个正斜杠( u [3] = lang </ code>),但这应该让您开始切割您的URL以进行操作和 重新组装。</ p>

有一些很好的例子这里。</ p>

当然,我的网站的本地化版本需要驻留在这些url路径下(在我的情况下,我更改了一些PHP 全局变量来考虑URL中的不同语言代码,因此引擎盖下的内容实际上是最小的)但这是一种让您开始分析/更改/替换您的URL的方法。</ p>

</ div>

展开原文

原文

TL;DR - Use some javascript to manipulate the url onclick, reassemble the URL the way you wish, reload new URL.

I did a bilingual shop once and inserted an 'es' or an 'en' into the path to signify Spanish or English, essentially as a URL parameter. Your goal is a bit more complicated (I'll assume it has to be) but this might get you started. You can see the shop here (not my design -- don't blame me. Much of it is offline at the owner's request (some legal stuff) but you should be able to navigate some pages and see the language toggle in effect.)

Clicking a language toggle triggers some simple Javascript as follows:

function switchLanguage(lang) {
  u = location.href.split('/');
  u[3] = lang;
  location.href = u.join('/');
}

And then an onclick is added to the language toggle links to direct onclick="switchLanguage('en')" or onclick="switchLanguage('es')", or whatever your URL injection is to be. Again, this is specific to my example where the URL parameter was going to follow the third forward slash (u[3] = lang), but this should get you started on dicing up your URL for manipulation and reassembly.

There are some excellent examples here.

Of course, the localized versions of my site needed to reside under those url paths (in my case, I changed some PHP global variables to account for the different language codes in the URL, so the under-the-hood stuff is really minimal) but this is one method to get you started on how to split/alter/replace your URL onclick.



只需使用IF语句,如果单击该按钮,URL将被更改!
每个url会导致使用不同语言的页面 。 如果我找对你</ p>
</ div>

展开原文

原文

Simply use the IF statement, if the button is clicked, the URLs will be changed! Each url leads to a page in different language. If I got you right

doulian8742
doulian8742 谢谢@Richard!
6 年多之前 回复
drs7798
drs7798 谢谢..我添加了它
6 年多之前 回复
dtcaw02086
dtcaw02086 这与我的理解有很大的不同。 我建议你将这个评论添加到主要问题中,因为它不够清楚!
6 年多之前 回复
douchan7552
douchan7552 如果url的一部分是'.nl / schoenen /'那么改变并转到'.com / shoes /'如果url的一部分是'.nl / jassen /'那么改变并转到'.com / jackets /'我希望 这更清楚了吗? 谢谢!
6 年多之前 回复



您正在使用的Url位于window.location对象中。 如果要重定向,检索它(例如window.location.href),使用字符串操作更改域并重定向窗口? </ p>

很抱歉,如果我没有正确理解您的问题。</ p>
</ div>

展开原文

原文

The Url you are curently on is in the window.location object. When you want to redirect, retrieve it (window.location.href for example), change the domain using string operations and redirect the window ?

Sorry if I havent understood your problem correctly.



您可以创建一个“翻译”当前网址的方法:</ p>

  function  translateUrl(string transArticleName){
var newTerm =“。com /”+ transArticleName +“/”;
return window.location.href.replace(“/。nl / [\ w] {1,} //”, newTerm);
}
</ code> </ pre>

或者您阅读文章名称并将其翻译成英文:</ p>

  function  translateUrl(string transArticleName){
var oldTerm = window.location.href.match(“/。nl / [\ w] {1,} //”)[0];
var aName = oldTerm.match(/ \ / [\ w] {1,} \ //)[0] .match(/ [^ \ /] {1,} /)[0]
var transArticleName = //翻译aName服务器端
var newTerm =“。com /”+ transArticleName +“/”;
返回window.location.href.replace(oldTerm,newTerm);
}
</ code> </ pre>

当你 我可以看到我不是正则表达式的主人,所以我确信这里有更好的方法可以使用它们。</ p>
</ div>

展开原文

原文

You could create a method which "translates" the current url:

function translateUrl(string transArticleName) {
    var newTerm = ".com/"+transArticleName+"/";
    return window.location.href.replace("/.nl/[\w]{1,}//", newTerm);
} 

Or you read the article name and translate it to english:

function translateUrl(string transArticleName) {
    var oldTerm = window.location.href.match("/.nl/[\w]{1,}//")[0];
    var aName = oldTerm.match(/\/[\w]{1,}\//)[0].match(/[^\/]{1,}/)[0]
    var transArticleName = //translate aName server side
    var newTerm = ".com/"+transArticleName+"/";
    return window.location.href.replace(oldTerm, newTerm);
} 

As you can see I'm not the master of regex' so I'm sure there is a nicer way to use them here.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐