In the data-id from pictures, store ID, for example. When you open the image in URL using JS add img_id=$ID. In the method ready when the page loads check for img_id in the URL and if there is, on the page look for the picture with this data-id and open it.