asales Expert Licensed User Longtime User Jul 13, 2020 #1 Is possible to use the back key and go to the previous URL? B4X: Sub Activity_KeyPress(KeyCode As Int) As Boolean If KeyCode = KeyCodes.KEYCODE_BACK Then 'How to back to the previous URL ?? End If End Sub Thanks in advance for any tip.
Is possible to use the back key and go to the previous URL? B4X: Sub Activity_KeyPress(KeyCode As Int) As Boolean If KeyCode = KeyCodes.KEYCODE_BACK Then 'How to back to the previous URL ?? End If End Sub Thanks in advance for any tip.
JohnC Expert Licensed User Longtime User Jul 13, 2020 #2 B4X: Sub Activity_KeyPress (KeyCode As Int) As Boolean If KeyCode = KeyCodes.KEYCODE_BACK Then 'back key pressed wv.Back 'webview.back Return True 'Return True to consume the event End If End Sub You could also add some code so before doing the wv.back, it will first check to see if the last navigated URL for webview is the first URL that webview navigated to, and if so that means webview is back at it's original starting point/url (meaning the user navigated back to the first page), so another wv.back would do nothing, so when this condition happens, don't consume the back-key and let android handle the back key. Last edited: Jul 13, 2020 Upvote 0
B4X: Sub Activity_KeyPress (KeyCode As Int) As Boolean If KeyCode = KeyCodes.KEYCODE_BACK Then 'back key pressed wv.Back 'webview.back Return True 'Return True to consume the event End If End Sub You could also add some code so before doing the wv.back, it will first check to see if the last navigated URL for webview is the first URL that webview navigated to, and if so that means webview is back at it's original starting point/url (meaning the user navigated back to the first page), so another wv.back would do nothing, so when this condition happens, don't consume the back-key and let android handle the back key.
drgottjr Expert Licensed User Longtime User Jul 13, 2020 #3 try to consume the keypress and inject window.history.back(); via webviewextras into your webview Upvote 0
JohnC Expert Licensed User Longtime User Jul 13, 2020 #4 drgottjr said: try to consume the keypress and inject window.history.back(); via webviewextras into your webview Click to expand... I didn't know that window.history.back works differently then webview.back. I thought they worked the same. Last edited: Jul 13, 2020 Upvote 0
drgottjr said: try to consume the keypress and inject window.history.back(); via webviewextras into your webview Click to expand... I didn't know that window.history.back works differently then webview.back. I thought they worked the same.
asales Expert Licensed User Longtime User Jul 13, 2020 #5 Thanks both! I found this thread too with CanGoBack function and problem solved! Upvote 0
JohnC Expert Licensed User Longtime User Jul 13, 2020 #6 So then the code will look like: B4X: Sub Activity_KeyPress (KeyCode As Int) As Boolean If KeyCode = KeyCodes.KEYCODE_BACK and CanGoBack Then 'back key pressed wv.Back 'webview.back Return True 'Return True to consume the event End If End Sub Upvote 0
So then the code will look like: B4X: Sub Activity_KeyPress (KeyCode As Int) As Boolean If KeyCode = KeyCodes.KEYCODE_BACK and CanGoBack Then 'back key pressed wv.Back 'webview.back Return True 'Return True to consume the event End If End Sub