Search code examples
javascripthtmlcsshyperlinkhref

How could I change a link on a webpage if the device is mobile? HTML/Javascript/CSS


I'm wanting to make it to where if the device is mobile (iPhone, Android, Windows, Etc.) it goes to a a different link than if it was a desktop device viewing the page.

For example, if I wanted to use an URL scheme to open instagram on a mobile device but the instagram website for a desktop device.

All help is appreciated!


Solution

  • Run Ilan's code like this

    <a href="javascript:testBrowser()>Link</a>
    

    where testBrowser() is a function containing his code.