1

My website is being ran in a mobile app within an iFrame. This app has a "back" button implemented, above the iFrame. Whenever this button is clicked, the API of the app will send my website an event, and I perform window.history.back() so the user goes back one page on my website, inside the iFrame.

The problem occurs when the user clicked the back button at the point where there is no page back anymore, in this case, instead of using the window.history.back() I want to send an event to the API to close the iFrame.

How do I know when "this is the last page"?

Thanks

Dennis
  • 3,044
  • 2
  • 33
  • 52
  • Have you seen this one? https://stackoverflow.com/questions/3588315/how-to-check-if-the-user-can-go-back-in-browser-history-or-not – Marcin Dec 21 '19 at 20:29
  • My idea is that you should be tracking the URL for yourself and work out whether this is the first page they visited - hence they cannot go back any further – Marcin Dec 21 '19 at 20:30
  • @Marcin Thanks for the link! I checked that thread out already, imagine if the users goes from : homepage > page2 > page3 > *back* page2 > *back* homepage > *back* (close Event). But the referrer will have the value of page 2 in this case. – Dennis Dec 21 '19 at 20:35
  • You can simply add different event to the "back" button when it's hompage. – A. Meshu Dec 22 '19 at 01:10
  • Hello @A.Meshu , but in the case of "homepage > page 2 > page 3 > homepage > page 4 > *back* homepage > *back* page 3 > ... I do not want to call the 'back' event at this point in time. Since there are more pages in the history to go back to that are still on my website – Dennis Dec 22 '19 at 15:51
  • Good Point. Can you set pages name with equal string at the beginning? the hompage won't hold that in his name. this way you would know how to react when user push back and the back dosen't hold that string in the name... – A. Meshu Dec 23 '19 at 10:39
  • That sounds like an idea, create my own, very simplistic, queue of pages visited perhaps. – Dennis Dec 23 '19 at 10:48

0 Answers0