0

i've read Modify the URL without reloading the page

but i don't really understand or maybe my scripts needs an other command to work properly.

I've got this script to load content in the #content-Div without reloading the page:

function contentloader(dataid) {
    $("#content").fadeOut(100).load("controller.php?id=" + dataid + "", {}, function () {
        $(this).fadeIn("slow");
    });
}

How can i manipulate the URL to.. like ?id="sitename" if someone hits the link "sitename" ?

And is there also a possibility to mark the clicked link as "current", so it gets for example the class "current" if the link got clicked, this is just for css.

URL-Modify is just for reloading the page (if someone do so) and he lands back where he was and of course for the "back" and "forward" functions in browsers.

Community
  • 1
  • 1
dstN
  • 332
  • 6
  • 21
  • You can read something for single page apps http://singlepageappbook.com/ like that... and then find a good framework (or write your own). I use meteorjs and the backbone router. – thinklinux Feb 07 '14 at 10:11

3 Answers3

0

You can achieve that using HTML 5. I don't know is there any other option available. Have a look on this http://spoiledmilk.com/blog/html5-changing-the-browser-url-without-refreshing-page/

  • Yeah, i found this on the other question here, but i don't know how to implement it in my script, thats my problem. – dstN Feb 07 '14 at 09:33
  • history.pushState(PAGE_STATE,PAGE_TITLE,YOUR_URL); try this :) – Karthik Surianarayanan Feb 07 '14 at 09:38
  • is there a place where to read about the different page_state's ? like "0" for default, "1" for "first next site" or something like that? i might be too new to jscript to understand that... maybe i should get rid of the ajax stuff, using this only because i wanted to test around with ajax and learning some new stuff but if this bangs my head out i should reconsider. – dstN Feb 07 '14 at 09:54
  • I just started working a few days ago with that. Usually i use the state option to have page data. To manipulate the URL i don't think it is necessary. – Karthik Surianarayanan Feb 07 '14 at 09:57
0

Use this plugin its very simple to add

http://benalman.com/projects/jquery-bbq-plugin/

Here is how to add this

http://benalman.com/code/projects/jquery-bbq/examples/fragment-basic/

Manish Kumar
  • 10,214
  • 25
  • 77
  • 147
0

Use core Javascript (condition: ie>8)

var stateObj = { foo: "bar" }; history.pushState(stateObj, "page 2", "bar.html");

Jain
  • 1,209
  • 10
  • 16