admin管理员组文章数量:1321070
UPDATE
Sorry my qusetion was unclear i have updated my question
I want to add a query string in the end of url using anchor
For example if i have url
www.mysite/home
And have anchors on this page
<a href='?page=1'>1</a>
<a href = '?page=2'>2</a>
.
.
<a href = '?page =x'>x</a>
When i click on these anchor link it directs me to Url
www.mysite/home?page=x
That what i want , I just want to add query string page
in the end of the url,
But in the case of
www.mysite/home?category=sports
Or
www.mysite/home?category=music
Then if i click on the same anchor link
It redirects me to
www.mysite/home?page=x
But i want it to direct me to
www.mysite/home?category=sports&page=x
And now if i again on any of those link like
<a href='?page=1'>1</a>
Then i want it to direct me to
www.mysite/home?category=sports&page=1
is their any simple solution to do this , Or i have to use any plex javascript code.
thanks
UPDATE
Sorry my qusetion was unclear i have updated my question
I want to add a query string in the end of url using anchor
For example if i have url
www.mysite./home
And have anchors on this page
<a href='?page=1'>1</a>
<a href = '?page=2'>2</a>
.
.
<a href = '?page =x'>x</a>
When i click on these anchor link it directs me to Url
www.mysite./home?page=x
That what i want , I just want to add query string page
in the end of the url,
But in the case of
www.mysite./home?category=sports
Or
www.mysite./home?category=music
Then if i click on the same anchor link
It redirects me to
www.mysite./home?page=x
But i want it to direct me to
www.mysite./home?category=sports&page=x
And now if i again on any of those link like
<a href='?page=1'>1</a>
Then i want it to direct me to
www.mysite./home?category=sports&page=1
is their any simple solution to do this , Or i have to use any plex javascript code.
thanks
Share Improve this question edited Jan 31, 2017 at 14:12 beginner asked Jan 31, 2017 at 13:11 beginnerbeginner 2,5084 gold badges32 silver badges54 bronze badges4 Answers
Reset to default 2It is simple.
var url ="www.mysite./home?page=1";
var result = url + (url.indexOf('?')== -1 ? "?page=1" : "&page=1")
window.location.replace(url);
url - is the string you want to open
You have to add all params to the link, like this:
<a href='?category=sports&page=1'>1</a>
<a href='?category=sports&page=2'>2</a>
.
.
.
<a href='?category=sports&page=x'>x</a>
I don't remend using this but I think this is the only solution:
<a href="Javascript: if (window.location.href.indexOf('page=')==-1) { window.location=(window.location.href+ (window.location.href.toString().indexOf('?')>-1 ? '&page=1': '?page=1'))}">click here</a>
本文标签: javascriptAdd query string to url using anchor linkStack Overflow
版权声明:本文标题:javascript - Add query string to url using anchor link - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742090819a2420256.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论