0

特定の URL を追跡するために、この JavaScript を使用しています。

$(document).ready(function(){
if(document.location.toString()=="http://www.mysite.com/DisplayCart.aspx")
....
....

しかし、私の問題は、たとえば http://www.mysite.com/PaymentDetails.aspx?Id=817328&PaymentMode=COD&delvoption=ship&ChildStoreID=などのページのグループを追跡したい場合です

http://www.mysite.com/PaymentDetails.aspx?Id=817329&PaymentMode=COD&delvoption=ship&ChildStoreID=

等々..

ここですべてのURLはaspxの後に異なりますか? これは、顧客固有のページ/顧客の注文固有のページと同じです。JavaScriptのみを使用したいことに注意してください。

4

2 に答える 2

0

文字列は?で分割できます:

if(document.location.toString().Split("?")[0]=="http://www.mysite.com/DisplayCart.aspx")

基本的に、2つの部分を?で区切って、最初の部分だけを比較します。

于 2013-03-02T07:23:31.317 に答える
0

残念ながら、Christian Stewartは機能しませんでしたが、以下のコードは機能しています。それがすべての場合にバグ料金になることを願っています、私はURLのすべての可能なケースについてそれをテストしています....また、それが特定の場合に機能しないかもしれないことがわかったら私に知らせてください...

$(document).ready(function(){

var align1 = document.location.toString(),

    delimiter = '?',
    start = 0,
    tokens1 = align1.split(delimiter).slice(start);

//alert(tokens1[0]);

//if(document.location.toString().Split("?")[0]=="http://www.mysite.com/DisplayCart.aspx")
if(tokens1[0]=="http://www.mysite.com/DisplayCart.aspx")
{
    alert("hi");
}
else{}
});

そして、Yaは助けてくれてありがとう。

于 2013-03-04T11:14:30.403 に答える