Detemine the previous page (i.e. referrer) in jQTouch

时光毁灭记忆、已成空白 提交于 2019-12-22 01:16:13

问题


I am trying to determine the previous page (e.g. the referrer) in order to decide whether to display the back button.

I tried to check for $('.current').data('referrer'), but it is not always set. In fact, it is often not set. history.previous and document.referrer do not seem to be set, either.

Could someone please enlighten me on this?


回答1:


I have been struggling on the same problem using referrer, but I did not get that. I came up with the following solution that does not force me to modify the jqtouch.js

$('body>div').bind('pageAnimationStart', function(e, data) {
  if(data.direction === 'out') {
    alert('referrer is : ' + e.currentTarget.id);
  }
});

the $('body>div') selector should select all the div that are direct child of the body, which in jqtouch are all the pages definitions. I found the name of the origin page in the event returned by pageAnimationStart in currentTargetId.

Would appreciate if somebody would tell me if I can be even more restrictive with the selector and if there is also a way of getting the current page.




回答2:


I didn't want to go down this path, but the only viable solution I can find is the internal variable (i.e. hist) that jQTouch keeps the browsing history. So, I made the following changes to jqouth.js (revision 146):

around line 256, just before the private functions section, insert:

function getHistory() { return hist; }

around line 625, just before submitForm: submitForm, insert:

getHistory: getHistory,

Then I can look at the browsing history with something like:

var previousPageID = jQT.getHistory()[1].id;

One caveat is, care should be taken not to accidentally maniplulate the history object.

EDIT:

The author has exposed the internal history object since the version on 14 October 2010, so it can be directly accessed, i.e. jQT.hist.




回答3:


Hmm...I can't comment, so this is with respect to William's answer of modifying the jqtouch.js.

I think I'll be easier to simply put:

hist: hist,

Where

getHistory: getHistory,

is to be placed.

And then there's no need to add the function. Just remember that you're accessing the history itself and not a function, so no need for the rounded brackets.

Then again, this really only applies to older versions of jqtouch.



来源:https://stackoverflow.com/questions/3499437/detemine-the-previous-page-i-e-referrer-in-jqtouch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!