JQuery Twitter / Facebook like page navigation

I really liked how the new Twitter and Facebook saved downloaded pages, instead dynamically loading content via ajax. I want to start rolling it over to my sites, but I don't know where to start.

Twitter and Facebook now have uri: http://twitter.com/#!/messages

$(document).ready(function () {

// Check if a hash exists already and if so load that page instead.
if(window.location.hash) {
    $("div#content").load(window.location.hash);
} else {
    // load the home page.
    $("div#content").load("http://localhost/home/");
}

// Allow menu to change url hash and load new content.
$('ul#menu li a').click(function() {
    $("div#content").load(window.location.hash);
});

});

html for the menu i have:

<ul id="menu">
    <li>< a href="#">logout</a></li>
    <li>< a href="#!/settings">settings</a></li>
    <li>< a href="#!/messages" class="notify">messages <span>3</span></a></li>
    <li>< a href="#!/profile">profile</a></li>
    <li>< a href="#!/" class="selected">home</a></li></ul>

Any idea how Facebook or Twitter does it?

+3
source share
2 answers

, , Ajax. Ajax - jQuery, , , . -

1) , "A". "A.txt".

2) , "B". "B.txt".

3) HTML-, jQuery Test.htm. :

<input type="button" class="LoadMyDiv" id="ButtonA" value="load A">
<input type="button" class="LoadMyDiv" id="ButtonB" value="load B">


 $(document).ready(function () {
       $(".LoadMyDiv").click(function() {
         $("#Adiv").load("A.txt");
         $("#Bdiv").load("B.txt");
 });
 });
<div id="ThisDiv"></div>
+1

.

0

Source: https://habr.com/ru/post/1767617/


All Articles