doggie brezy doggie brezy - 24 days ago 11
jQuery Question

javascript history.pushState not working for iframe

I want to run a

pushState
and it works fine but when I load the page through an iframe element it refused to work. This is how my code looks like

$('a[href]').click(function){
newHref = $(this).attr('href');
history.pushState('', '', newHref);
})


But it's not working, Please anyone with an idea of how to achieve this?

Answer

Using history.pushState() changes the url of the iframe source page. To change the main url in the address bar you have to address it to the parent so use this

window.parent.history.pushState();
Comments