2016-11-08 91 views
0

我想運行一個pushState,它工作正常,但當我通過iframe元素加載頁面時,它拒絕工作。這是我的代碼看起來像javascript history.pushState不適用於iframe

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

但它不工作,請任何人有一個想法如何實現這一目標?

回答

1

使用history.pushState()改變iframe的源頁面的URL。要更改地址欄中的主要網址,您必須將其解決到父級,請使用此

window.parent.history.pushState(); 
0

你應該只需要保持所謂的包裹在click事件括號內的功能...

$('a[href]').click(function(e){ 
    e.preventDefault(); 
    newHref = $(this).attr('href'); 
    history.pushState('', '', newHref); 
}); 
相關問題