function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Amith Kumar 7Amith Kumar 7 

how to detect user has pressed back button in mobile app

I have been developing lwc component for salesforce mobile. I would like to know the code on how to know user has pressed back button
VinayVinay (Salesforce Developers) 
Hi Amith,

Try below snippet of JS.
window.onhashchange = function() {
 // logic
}

function goBack() 
{ 
window.location.hash = window.location.lasthash[window.location.lasthash.length-1]; 
// logic
window.location.lasthash.pop(); 
}

Please mark as Best Answer if above information was helpful.

Thanks,
Amith Kumar 7Amith Kumar 7
Hi Foster,

Thanks for your reply. I need to write a custom logic when user clicks back button on the top left. Please find the attached screenshot highlighted in yellow color.


User-added image

Thanks,
Amith Kumar
Ethun HuntEthun Hunt
I also faced the same problem but now I got the best answer. Thank you for your solution! Visit my website on WhatsApp Modified Versions (https://apksforwamods.com).