Magnific-popup: Add history.pushState

Created on 12 Nov 2013  路  7Comments  路  Source: dimsemenov/Magnific-Popup

Can you add history states to ajax/images like fb do.

References
history.pushState(stateObj, "page 2", "bar.html");
http://www.asual.com/jquery/address/

Most helpful comment

None of the code I found on the web worked with Magnific Popup's gallery mode, so I've hacked my own solution:

http://eugenedae.github.io/Magnific-Popup-History-API-Demo/
https://github.com/EugeneDae/Magnific-Popup-History-API-Demo

All 7 comments

I don't really think it's a good idea to include this by default.I think it's better to use the callback methods.

We are implementing it with callback methods for ajax/inline-frames/images, it would have been great if it was handled within Magnific Popup by default, would make it a lot more great.. just a suggestion. Thanks.!!

Code recommendation

----to be placed after

if(!item.src) {
    item.src = item.el.attr('href');
}

----Add---

//line added to change url, compensated by window.history.back(); in _close block
window.history.pushState(item.src,item.src,item.src); 

// block added to add support for appending secret link at the end of url so as to tell that content is for popup
if(mfp.st.queryAppend != false){    
    if(item.src.indexOf("?")>0){item.src+='&';}else{item.src+='?';}
    item.src+=mfp.st.queryAppend||'content_type=popup';
}

--Add this in _close: function()---

// line added to compensate window.history.pushState(item.src,item.src,item.src); added while loading src
window.history.back(); 

Thanks for sharing, I'll consider implementing something like this as a separate excludable module.

any development over this idea?
I've tried to implement, but broken when playing with it for more deep click and link.

http://beritagar.com

I have working code,
ajax based: http://www.lastdates.com/

Note:

  1. Its just a simple working solution, not very robust.
  2. In iframe we can't change domain in url of address-bar, hence I show
    address in #hash

Hope you get directions.

None of the code I found on the web worked with Magnific Popup's gallery mode, so I've hacked my own solution:

http://eugenedae.github.io/Magnific-Popup-History-API-Demo/
https://github.com/EugeneDae/Magnific-Popup-History-API-Demo

Was this page helpful?
0 / 5 - 0 ratings

Related issues

BorislavZlatanov picture BorislavZlatanov  路  4Comments

landitus picture landitus  路  3Comments

tillilab picture tillilab  路  4Comments

samholmes picture samholmes  路  5Comments

vdotm picture vdotm  路  5Comments