Javascript 在asp.net webform中添加一个jquery表单,该表单需要使用php重定向到站点
我不想使用代码隐藏对查询字符串进行重定向,因为我将使用wysiwug编辑器来实现这一点。提交后,希望它重定向到 名字 请专家建议我如何使用javascript或jquery重定向querystring。请写详细信息,因为我在这方面是全新的。步骤1:在Javascript 在asp.net webform中添加一个jquery表单,该表单需要使用php重定向到站点,javascript,jquery,asp.net,.net,Javascript,Jquery,Asp.net,.net,我不想使用代码隐藏对查询字符串进行重定向,因为我将使用wysiwug编辑器来实现这一点。提交后,希望它重定向到 名字 请专家建议我如何使用javascript或jquery重定向querystring。请写详细信息,因为我在这方面是全新的。步骤1:在中放置两种方法: <script type="text/javascript" language="javascript"> // return the value of a parameter based on the name you
中放置两种方法:
<script type="text/javascript" language="javascript">
// return the value of a parameter based on the name you pass in
function getParameterByName(name) {
// use regular expression to replace [ with \[, and replace
// ] with \], you get this if you
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
// make a new regex that strips out the querystring parameters
// the [\\?&] looks for the beginning ? or & characters,
// then the name of the parameter (you passed it in to the method)
// then the "=([^&#]*)" is looking for = followed by any character
// except & or #. Because there are parentheses around this part
// it will remember the match in a match group.
var regexS = "[\\?&]" + name + "=([^&#]*)";
// this converts the regular expression string into a RegExp object
var regex = new RegExp(regexS);
// execute the regular expression against the URL
var results = regex.exec(window.location.search);
if(results == null) {
// it didn't find the parameter you passed in
return "";
} else {
// we got a match! The value of your parameter is in the
// results array (parentheses in the regexS above told the
// regex to store it there. We do a quick replace at the end
// to convert the + character to a space, because it is URLEncoded
return decodeURIComponent(results[1].replace(/\+/g, " "));
}
}
// call this method to do the redirect
function redirectBasedOnParameters() {
// read the value of the parameter named 'first'
var var1 = getParameterByName('first');
// read the value of the parameter named 'last'
var var2 = getParameterByName('last');
// redirect the browser
window.location = "http://abc.somedomainname.com?first=" + var1 + "&last="+ var2
}
</script>
<html>
<head>
<script type="text/javascript">
// put the JavaScript code mentioned above inside here
</script>
</head>
<body onload="redirectBasedOnParameters()">
<h1>Hello World!</h1>
</body>
</html>