Javascript 在Backbone.js中检查推荐人
我正在为我的web应用程序使用backbone.js,特别是路由和历史 所以我有一个类似的URL 在我的router.js中,我有一条类似Javascript 在Backbone.js中检查推荐人,javascript,backbone.js,referrer,Javascript,Backbone.js,Referrer,我正在为我的web应用程序使用backbone.js,特别是路由和历史 所以我有一个类似的URL 在我的router.js中,我有一条类似 search: function () { /* do something */ /* Can I check here, whether I came to this page using Backbone's navigate() or by pasting the url in the urlbar */ } 在这个函数
search: function () {
/* do something */
/* Can I check here, whether I came to this page using Backbone's navigate()
or by pasting the url in the urlbar */
}
在这个函数中,是否有一个内置的主干来检查我是如何进入该页面的:通过backbone.router.navigate或通过在浏览器的url栏中粘贴url/单击将我带到那里的链接
我试过document.Referer,但它是
>> document.referrer
""
在这两种情况下。您可以尝试保存最新的值:
$(function(){
var lastPage = 'stackoverflow.com';
var routesObject = {
'help': 'helpFun',
'search': 'searchFun'
};
var Router = Backbone.Router.extend({
initialize: function() {
this.bind('all', function(route) {
lastPage = window.location.hash.split('#')[1];
});
},
routes: routesObject,
searchFun: function(){
console.log(lastPage);
},
helpFun: function() {
console.log(lastPage);
}
});
var router = new Router();
Backbone.history.start({pushState:false});
});
如果导航到your.domain.com/yourappsearch,然后再导航到your.domain.com/yourapphelp,您将在控制台中看到最近输入的路由