1

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?

2

3 Answers 3

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.

3
  • I actually think you might need to relax the selector, rather than restrain it: each page does not have to be a <div>; it can be, say, a <form> or other tags. So, body>* may actually be more appropriate? Nov 11, 2010 at 13:16
  • +1 for it being a good suggestion if I just want the previous page. Thanks! Nov 11, 2010 at 13:17
  • Was under the impression that for jQTouch to function properly every page had to be in it's own <div>, that's what tell tQTouch where a page start and finish.
    – Raymond
    Nov 23, 2010 at 4:10
1

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.

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.