'Window.open() to trigger phone SMS/Call/Email app not working in Chrome on Android on Page Load - Using ReactJS

This is my code snippet.

else if (item.title === 'Text') {
             try {
                     window.open(`sms:${item.link}`,'_self')
             } catch (error) {
                 console.log(error)
             }

When this function is executed on a page load, it does not automatically trigger the SMS app. This issue only occurs on Chrome Android browser. Works for Safari, Mozilla, and Opera. When executed as an onClick, it works perfectly on all browsers, including Chrome on Android. Only facing an issue on page load in Chrome.

The framework I am using is React JS.



Solution 1:[1]

For some strange reason, Andriod doesn't allow dynamically created SMS: links to work! Whereas if you copy a complete link in an anchor link (i.e <a href="sms://1234/?body=body">Click for SMS</a>) or window.open("sms://1234/?body=body") (if the link is correctly formed) it works. It wasted half of my day to find a way around it so far

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Bruce