Solved

jquery update URL

Posted on 2011-03-23
2
360 Views
Last Modified: 2012-05-11
Hey guys,

Is it possible to update a URL with jQuery after a link is clicked on?

I have a content scroller in my web page that moves to different parts of the content, from navigation links (no page refresh) Can i update to the URL to have make a permalink to that exact part?

E.g.
Before click:  URL:  http://www.test.com/
After click:     URL:  http://www.test.com/2

So that if anyone loads the /2 address it will load the 2nd part of the content scroller.

Thanks
0
Comment
Question by:dev09
2 Comments
 
LVL 40

Accepted Solution

by:
gurvinder372 earned 250 total points
ID: 35197307
If the URL you are refering to is the URL of page
then
<a href="javascript:changeURL()">

function changeURL()
{
   location.href = location.href + "/2";
}


0
 
LVL 13

Assisted Solution

by:darren-w-
darren-w- earned 250 total points
ID: 35197688
Jquery:

 
<html>
    <head>
        <title>test</title>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
        <style type="text/css">
        </style>
        <script type='text/javascript'>
            $(function(){                 
                $("a").click(function(){
                    $(this).attr("href",$(this).attr("href")+"/2")
                })
            });

        </script>
    </head>
    <body>
        <a href="#">location</a>
    </body>
</html>

Open in new window


this will though keep appending to the url on subsequent clicks, but does the same as above
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question