Note that there are some explanatory texts on larger screens.

plurals
  1. POBackbone.js - Access referrer in controller function
    primarykey
    data
    text
    <p>I have a list of products (index view) and when a user clicks on a product, a Lightbox opens (show view). Now, when the user closes the lightbox, I want to redirect him back to the page he came from. The problem is that the Lightbox might have been opened from several different places. It's best demonstrated with an example:</p> <p>Product "Foo" appears on 3 different pages:</p> <pre><code>/ (the home page) /tag/bar (all products tagged with "bar") /tag/baz/page-3 (all products tagged with "baz", paginated) </code></pre> <p>Now I have to decide where to redirect the user when the Lightbox closes. At this stage, there is no information available about which page the Lightbox was opened from.</p> <p>So I figured I save a "returnTo" path when opening the Lightbox (rendering the show view). In the controller function, which is triggered by the hash change and renders the show view, I can't seem to get to any "referrer" information, though.</p> <p>Is there any way to see what page triggered the hash change? Or is there a better way to solve this problems?</p> <p>All suggestions are appreciated! :)</p> <p>EDIT:</p> <p>I solved the problem by setting a cookie. The cookie is set anytime a index site (might be any of the three mentioned above) is visited. Then, when the Lightbox is closed, the user is redirected to the cookie value, which is the last opened index site. It would be great, though, if there was a way built in to Backbone.js to "remember" pathes somehow. Julien mentioned in one of the comments that it might be possible to add such functionality.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload