0

I have a gallery content type, it references a number of images. When viewing gallery content, a View renders a gallery image, and a pager set to display a single item at a time allows the user to go back and forth with a link that will change the url.

As a user, I can now copy the URL and send it to someone else, who will see exactly the same image.

Problems show up however, when we decide to load only the new image, instead of the whole page, with JS. Since we no longer change the url, the JS-using user will remain at page=0 all the time, and can no longer share this URL as intended.

I have two suggestions of my own, but I haven't implemented either yet, and would love to hear either comments on those, different answers, or just votes on whichever answer you think is the best.

0

When using Javascript, the next/previous button could manipulate the # part of the URL with a page=X variable, and then if this is sent somewhere using a service like facebook or twitter, we just parse the #page=X into ?page=Y instead. If the url is copied directly, then we manipulate the copied text with JS to remove the # and move it's value into ?.

I believe I've seen such JS url-mangling practices before, but I also though that browsers protected the clipboard from manipulation with JS.

0

With Javascript, I could manipulate the # value of the URL without triggering a page reload. Using this, a custom Javascript pager could be implemented, that will override the ?page value with any #page value instead. Unfortunately that would mean loading two images. This way, paging with JS will update the #page value, and this url can then shared and get the intended behavior.

4
  • I haven't implemented a custom pager for views before, but does it work on the client side? The # part of a URL isn't sent to the server so there would have to be some client-side manipulation/loading of the view whenever the # portion of the url changes, or whenever a page is visited directly – Clive May 16 '12 at 14:41
  • Your right, I didn't consider that. A custom pager doesn't make sense at all then. Unless you'll do it, I'll post a different suggestion then. – Letharion May 16 '12 at 15:05
  • I think it's still valid, just not the # part...for HTML5 browsers it is possible to modify the url without refreshing the page; it seems you might be able to use that technique in place of the # if that makes sense? – Clive May 16 '12 at 15:11
  • Yeah, but the custom "paging" would need to be implemented client side instead, so that a link to ?page=Y#page=X will start at Y, but then move to X. I've updated the answer to remove the Views reference. – Letharion May 17 '12 at 8:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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