browser back acts on nested iframe before the page itself - is there a way to avoid it?

后端 未结 6 867
再見小時候
再見小時候 2020-12-13 12:54

I have a page with dynamic data loaded by some ajax and lots of javascript.

the page contains a list from which the user can choose and each selected value loads n

6条回答
  •  佛祖请我去吃肉
    2020-12-13 13:39

    The accepted answer does not seem to work if you try to set a cross-domain URL for the IFrame. As a workaround, I detached the IFrame from the DOM before setting the src (using jQuery).

    // remove IFrame from DOM before setting source, 
    // to prevent adding entries to browser history
    var newUrl = 'http://www.example.com';
    var iFrame = $('#myIFrame');
    var iFrameParent = iFrame.parent();
    
    iFrame.remove();
    iFrame.attr('src', newUrl);
    iFrameParent.append(iFrame);
    

提交回复
热议问题