back button inside a iframe using history.js

前端 未结 1 1135
盖世英雄少女心
盖世英雄少女心 2021-01-16 07:34

I am doing a project in RoR. That project is inside a iFrame. In that iframe have forward and back button. When I click backward button, the iframe content should go back bu

相关标签:
1条回答
  • 2021-01-16 08:04

    you may like to use the window.history object

    iframe.contentWindow.history.go(-1); // back
    iframe.contentWindow.history.go(1);  // forward
    

    so your back button can be modified as \

    $('#back-btn').on('click', function () {
        iframe.contentWindow.history.go(-1);
                     or
        iframe.contentWindow.history.back(); 
    });
    

    and your forward button can be modified as

    $('#forward-btn').on('click', function () {
      iframe.contentWindow.history.forward();
                    or
      iframe.contentWindow.history.go(1);
    });
    

    Cheers !

    0 讨论(0)
提交回复
热议问题