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?
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.
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
.
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.