android - JavaScript/JQuery Enable backbutton behaviour for a iframe in Cordova -


i developing webview application in cordova. webview app has iframe showing content website. layout of webview app, black portion iframe

<body style="background-color: #f8f8f8"> <div id="web_container">     <iframe id="main_content"         src="https://www.mycollegepicks.in/home"         style="margin: auto auto; overflow: hidden; border: 1px solid #f8f8f8"></iframe> </div> <div id='error' style='display: none'></div>    <div id="menu_wrapper" style="min-height: 40px">     <div>         <img class="menu_item_img" src="img/home.png"             style="width: 36px; padding: 2px;" id="home_btn">     </div>     <div>         <img class="menu_item_img" src="img/arrow_left.png"             style="width: 36px; padding: 2px;" id="back_btn">     </div>     <div>         <img class="menu_item_img" src="img/refresh.png"             style="width: 36px; padding: 2px;" id="reload_btn">     </div>     <div>         <img class="menu_item_img" src="img/arrow_right.png"             style="width: 36px; padding: 2px;" id="forward_btn">     </div>     <div>         <img class="menu_item_img" src="img/shut_down.png"             style="width: 36px; padding: 2px;" id="logout_btn">     </div> </div> </div> 

i have written following js -

$( "#logout_btn" ).click(function() {   showtoast('logging out', 'info');   console.log("logout button clicked");   logout_user();  }); $( "#reload_btn" ).click(function() {   showtoast('reloading page', 'info');   console.log("reload button clicked");   $( '#main_content' ).attr( 'src', function ( i, val ) { return val; }); });  $( "#home_btn" ).click(function() {   console.log("home button clicked");   $( '#main_content' ).attr( 'src','https://www.mycollegepicks.in/home?app=1&tab_type=home'); });  $( "#back_btn" ).click(function() {   console.log("back button clicked");   iframehistory = document.getelementbyid("main_content").contentwindow.history.length;   if(iframehistory)     document.getelementbyid('main_content').contentwindow.history.back();   writelog("iframehistory "+iframehistory);   popeyelogger('iframe history length '+iframehistory,'info'); }); $( "#forward_btn" ).click(function() {   console.log("forward button clicked");   iframehistory = document.getelementbyid("main_content").contentwindow.history.length;   if(iframehistory)     document.getelementbyid('main_content').contentwindow.history.forward();   writelog("iframehistory "+iframehistory);   popeyelogger('iframe history length '+iframehistory,'info'); }); 

but clicking on backbutton redirects previous page instead of iframe page back.

note : in iframe every page load , change made via ajax. on every ajax push url browser state.


Comments