I have a main page that contains several iframes and those iframes also have multiple iframes. iframes load with dynamic data.now the requirement is that when i click on the back button of browser then that give an alert(this functionality is not allowed). so that the previous iframe can't load. so how can i do this??
Asked
Active
Viewed 3,273 times
1
-
Simply dont use iframes... – Jonas Wilms Sep 21 '16 at 05:41
-
first why you are using `iframes` when u have other option as `div`. – Rishal Sep 21 '16 at 05:44
-
1@Jonasw Sometimes you have no choice when it comes to handle third party widget and this has nothing to do with question – A. Wolff Sep 21 '16 at 05:45
-
Look at [window history api](https://developer.mozilla.org/en-US/docs/Web/API/Window/history) using pushstate and popstate event – A. Wolff Sep 21 '16 at 05:46
-
using history is not reliable when user refreshes window it keeps adding to history array – A.T. Sep 21 '16 at 05:55
2 Answers
1
Based on iFrame purpose which is an HTML document embedded inside another HTML document. So an IFrame behaves like a window with its own independent content. In jQuery I did this and works for me. hope that would be useful.
$(window.parent.window).on('popstate', function () {
//Some codes
});
But should know that "popstate" event of the window is fired when the active history entry changes. So it works for both backward and forward navigation.

Ali Tabandeh
- 86
- 1
- 3
0
assuming you have no prior condition to check iframe content
window.onbeforeunload = function() {
return 'this functionality is not allowed';
}

A.T.
- 24,694
- 8
- 47
- 65
-
This event is fired not only on backward navigation. It would be fired if you close tab/window, forward or refresh – A. Wolff Sep 21 '16 at 05:47
-
hmm I know, but that's the first solution come to my mind. Looking for further enhancements do you have any idea ? :) – A.T. Sep 21 '16 at 05:50
-
Something like [that](http://stackoverflow.com/a/18382442/1414562) but would really depends OP expected behaviour – A. Wolff Sep 21 '16 at 05:52
-
-