I need to modify the query string,
from: http://server/test/default.aspx
http://server/test/default.aspx?videoplay=20
or
from : http://server/test/default.aspx?toolPlay=1233136844420765
http://server/test/default.aspx?videoplay=20&toolPlay=1233136844420765
ie. add videoplay=20&
in between the query string
through jQuery. I have tried the .replace
function but there is 开发者_如何学Goproblem - I cannot find the correct regex. Can anyone provide a better approach or provide a regex for ".aspx?"
Well, what I would do is this:
if (url.indexOf('?') != -1) {
url += "&videoplay=20";
} else {
url += "?videoplay=20";
}
It doesn't use a regex, and it handles the case where the url does not contain a query string already.
You need to escape both the .
and the ?
as they are special regex characters:
\.aspx\?
However, you can simply append &videoplay=20
to the end of the URL. The effect will be the same, unless the serverside code is looking at the index of querystring variables (which is very poor practice).
精彩评论