配列を返すjavascript関数があります。
私が知りたいのですが
- (a)OnInitまたはOnloadでJavascript関数を呼び出す方法
- (b)javascript関数は配列を返し、それをc#コードの配列内に格納したいと思います。
提案してください。
ありがとう。
Update1:Javascript関数は以下のようなものです。
function RenderUrl()
{
var url = "http://myurl.com/mypage?Id=420&Width=30"; //this is a dummy url.
var qsBegin = url.indexOf("?");
var qsPattern = new RegExp("[?&]([^=]*)=([^&]*)", "ig");
var match = qsPattern.exec(url);
var params = new Array();
while (match != null)
{
var matchID = match[1];
if ( matchID.charAt(0) == "&" )
{
matchID = matchID.substr(1);
}
if ( params[match[1]] != null && !(params[match[1]] instanceof Array) )
{
var subArray = new Array();
subArray.push(params[match[1]]);
subArray.push(unescape(match[2]));
params[match[1]] = subArray;
}
else if ( params[match[1]] != null && params[match[1]] instanceof Array )
{
params[match[1]].push(unescape(match[2]));
}
else
{
params[match[1]]=unescape(match[2]);
}
match = qsPattern.exec(url);
}
return params;
}
更新2:これまでの私のc#コード(期待どおりに機能していませんが、現在チェックしています)
private void ParseUrl(string Url)
{
int WhereToBegin = Url.IndexOf("?");
string pattern = @"[?&]([^=]*)=([^&]*)";
Regex rgx = new Regex(pattern, RegexOptions.IgnoreCase);
MatchCollection matches = rgx.Matches(Url);
while (matches != null)
{
string matchID = matches[0].ToString();
if (matchID.Substring(0, 1) == "&")
{
matchID = matchID.Substring(1);
}
//Push to the new array named PARAMS here (under construction)
..
..
//End array construction.
matches = rgx.Matches(Url);
}
//Finally return the array once it is working fine.
}