user222427
user222427

Reputation:

jscript how to find current url and redirect + QueryString

I'm trying to reload the same page with new parameter for example.

www.mysite.com/hi/hi/yo/default.aspx to redirect to www.mysite.com/hi/hi/yo/default.aspx?querystring=helloworld.

What I really need to do is redirect to www.mysite.com/hi/hi/yo/default.aspx to redirect to www.mysite.com/hi/hi/yo/default.aspx?Myparam=yellow and i dont want to hardcode `www.mysite.com/hi/hi/yo/default.aspx

Thanks

Upvotes: 0

Views: 66

Answers (1)

Aminadav Glickshtein
Aminadav Glickshtein

Reputation: 24590

This will redirect www.mysite.com/hi/hi/yo/default.aspx to www.mysite.com/hi/hi/yo/default.aspx?Myparam=yellow

location.href=location.href + '?MyParam=yellow'

You can do also:

if (location.href=='http://www.example.com/hi/hi/yo/default.aspx')
    location.href=location.href + '?MyParam=yellow'

Upvotes: 1

Related Questions