2013-09-23 1 views
1

RoR에서 프로젝트를하고 있습니다. 그 프로젝트는 iFrame 안에 있습니다. iframe에는 앞으로 및 뒤로 버튼이 있습니다. 뒤로 버튼을 클릭하면 iframe 콘텐츠가 다시 돌아가지만 전체 브라우저 페이지로 되돌아 가지 않습니다. "histroy.js"플러그인을 사용 중입니다. 그러나 나는 그것을 어떻게 사용하는지 모른다.history.js를 사용하여 iframe 내부의 뒤로 버튼

$('#back-btn').on('click', function() { 
    History.back(); 
}); 

$('#forward-btn').on('click', function() { 
    History.forward(); 
}); 

$("a").click(function() { 
    n = 1; 
    q = n++; 
    var s = $(this).attr("href"); 
    var o = 'History.pushState({state:' + q + ',rand:Math.random()}, "State 1", \"' + s + '\");' 
    $("#z").empty().append('<button onclick=\'javascript:' + o + '\'>sds</button>'); 
    $("#z button").click(); 


    //this is for checking log 
    (function (window, undefined) { 

     var 
     History = window.History, // Note: We are using a capital H instead of a lower h 
      State = History.getState(), 
      $log = $('#log'); 

     // Log Initial State 
     History.log('initial:', State.data, State.title, State.url); 

     // Bind to State Change 
     History.Adapter.bind(window, 'statechange', function() { // Note: We are using statechange instead of popstate 
      // Log the State 
      var State = History.getState(); // Note: We are using History.getState() instead of event.state 
      History.log('statechange:', State.data, State.title, State.url); 
     }); 
    })(window); 
}) 

참고 :

내 코드는 이것이다 때때로 나는 아약스 전화를 사용하고 있습니다.

지원해 주셔서 감사합니다.

답변

1

당신이 window.history

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

그래서 당신의 뒤로 버튼이 \

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

으로 수정 될 수 객체와 앞으로 버튼을 사용하실 수 있습니다은

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

으로 수정 될 수 있습니다 건배!

+0

답변 해 주셔서 감사합니다. 아약스에서 작동할까요? – Selvamani

+1

iframe 외부에서 코드를 실행하는 경우에만 작동하지 않습니까? –

+0

Kevin이 맞습니다. iframe 외부에서만 작동합니다. –

관련 문제