未安装Viber桌面应用时,viber://chat?number=链接无法跳转至Viber官网主页的问题
viber://chat?number= Link Fallback When Viber Desktop Isn't Installed Hey there, let's break down why this is happening and how to fix it:
Why This Happens
Viber's custom URL scheme (viber://) only works if the Viber desktop app is already installed and has registered this protocol with your system. If the app isn't present, your browser/OS has no built-in rule to redirect you to the Viber download page—custom protocols don't come with automatic fallback behavior out of the box.
How to Implement the Fallback You Want
To get the "redirect to download page when Viber isn't installed" behavior, you'll need to add a bit of frontend JavaScript to handle the link click and fallback logic. Here's how to do it step by step:
First, replace direct
viber://links with a click handler
Don't let users click the rawviber://link directly. Instead, use a button or styled link that triggers a JavaScript function.Add the fallback logic code
Here's a working example you can adapt:// Target your link/button by ID document.getElementById('open-viber-chat').addEventListener('click', function(e) { e.preventDefault(); const targetNumber = '+1234567890'; // Replace with your target number (include country code!) const viberDeepLink = `viber://chat?number=${targetNumber}`; const viberDownloadPage = 'https://www.viber.com/download/'; // Try to open Viber window.location.href = viberDeepLink; // Set a timer to check if the app opened successfully setTimeout(() => { // If we're still on the same page, the app didn't open—redirect to download window.location.href = viberDownloadPage; }, 1500); // 1.5 seconds is enough time for the system to attempt to launch Viber });Tweak for better user experience
- Add a small loading message like "Opening Viber..." right after the click, so users know something's happening
- Note that some browsers might block the custom protocol launch—you can add a fallback message like "If Viber doesn't open, click here to download it" alongside the automatic redirect
Quick Notes
- Make sure your target number includes the full international country code (e.g., +86 for China, +1 for the US) in the deep link—otherwise Viber might not recognize it correctly
- This approach works for most custom app protocols (WhatsApp, Telegram, etc.) since they all have the same "no built-in fallback" limitation
内容的提问来源于stack exchange,提问作者deny Vice




