Solved

jquery update URL

Posted on 2011-03-23
2
358 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

This article will show, step by step, how to integrate R code into a R Sweave document
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

910 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now