如何创建可收藏的动态div标签?

时间:2014-04-20 09:44:14

标签: javascript php jquery html ajax

在gmail中,我们可以看到,如果我们打开邮件,地址就会改变 https://mail.google.com/mail/u/0/#inbox https://mail.google.com/mail/u/0/#inbox/14552c232aa5a9f4 {{3}} 没有重新加载整个页面,也就是说我可以在动态的div中为内容添加书签

function load(thediv,thefile) {
   if (window.XMLHttpRequest) {
        xmlhttp = new XMLHttpRequest();
   }
   else 
   {
        xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
   }
   xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState ==4 && xmlhttp.status == 200){
            document.getElementById(thediv).innerHTML = xmlhttp.responseText;
        }
   }
   xmlhttp.open('GET',thefile,true);
   xmlhttp.send();

 }

我已经尝试过这个ajax代码来将动态内容加载到div ...但我无法将其加入书签。 我怎么能在我的网站上做到这一点?

1 个答案:

答案 0 :(得分:2)

此方法称为“pushstate”。有关详细信息,请参阅thisthis