0

アンバーサンドが間にあるファイルを開く際に問題があります。

var attachment = "attachment;" + "&test& incident&.txt";

 HtmlPage.Window.CreateInstance("foo2", new object[] { Id.ToString(), attachment });


function foo2(theAlert, type) {
            alert(type);
            window.open('fileViewer.aspx?Id=' + theAlert + '&Type=' + type);

        }

別のページでタイプを取得しようとすると、「添付ファイル」のみが取得されます。アンパサンドの前の単語を取るからです。私のファイル名がありません。アンパサンドなしでファイル名を指定すると、ファイルを開くのに問題はありません。

誰か助けてください。

前もって感謝します。

4

2 に答える 2

1

使用できますencodeURIComponent

encodeURIComponent() 関数は、URI コンポーネントをエンコードします。

この関数は、特殊文字をエンコードします。さらに、

次の文字: , / ? : @ & = + $ #

window.open('fileViewer.aspx?Id=' + theAlert + '&Type=' + encodeURIComponent(type));
于 2013-08-27T09:34:42.213 に答える
0

次のことを試してください。

window.open("fileViewer.aspx?Id=" + theAlert + "&Type=" + encodeURIComponent(type));

encodeURI から encodeURIComponent に変更されました:

  • encodeURI は、完全な URI での使用を目的としています。
  • encodeURIComponent は、区切り記号 (; / ? : @ & = + $ , #) の間にある任意の部分である .. まあ .. URI コンポーネントで使用することを意図しています。
于 2013-08-27T09:31:46.803 に答える