Solved

jquery update URL

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

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 …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

831 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