Here is an example.
1) I open google.com. Object looks like this:
{
url: 'https://www.google.com/',
previous: '',
referrer: ''
}
2) Then I click on the link /news
and the object looks like this:
{
url: 'https://www.google.com/news',
previous: 'https://www.google.com/',
referrer: 'https://www.google.com/'
}
3) Then I open a new tab and go to https://stackoverflow.com/ and the object looks like this:
{
url: 'https://stackoverflow.com/',
previous: 'https://www.google.com/news',
referrer: ''
}
How to achieve it? I tried with window.localStorage
but it doesn't work.
Please try Backbone model, routing and HTML5 History API.
I am showing how to achieve the First Step:
var model=Backbone.Model.extend({
defaults:{
url: '',
previous: '',
referrer: ''
},
get_url:function(){
var self=this;
self.get_url=window.location.href;
}
});
var obj=new model(); //create instance of Model
obj.set('url',obj.get_url); // set the url value to model attribute
if You want the previous Attribute value,
obj.previousAttributes();
And Follow the same steps, set all other url attribute value to model and get the values.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.