简体   繁体   English

如何为社交媒体网站的链接编写代码:如果是移动应用程序,则为移动应用程序;如果是台式机,则为标准URL?

[英]How to code a link for social media site: mobile app if mobile, and standard URL if desktop?

How do I make a link on a website that has two possible outcomes depending on which type of device you are using (mobile app vs. native). 如何在网站上建立链接,根据您使用的设备类型(移动应用程序与本机类型),该链接有两种可能的结果。


Mobile 移动

<a href="fb://profile/6815841748">Facebook</a>
<a href="instagram://user?username=barackobama">Instagram</a>
<a href="twitter://813286">Twitter</a>

If clicked on desktop, I get: "There is no application set to open the URL" 如果在桌面上单击,我将得到: “没有设置用于打开URL的应用程序”



Native 本机

<a href="https://www.facebook.com/6815841748">Facebook</a>
<a href="https://www.instagram.com/barackobama">Instagram</a>
<a href="https://www.twitter.com/813286">Twitter</a>

This redirects to social media site in browser; 这将重定向到浏览器中的社交媒体网站; not in app for mobile. 不在移动应用中。



I'm not sure if this is something I can do with pure HTML5 or use jQuery/Javascript? 我不确定这是我可以使用纯HTML5还是使用jQuery / Javascript来完成?

I also don't know if I need to write mobile-app URLs specific to each OS (iOS/Android/Windows,etc). 我也不知道是否需要编写特定于每个操作系统(iOS / Android / Windows等)的移动应用程序URL。 I only have iOS to test on. 我只有iOS可以测试。


Note: I'd prefer not to use CSS width, because I feel it is not best practice. 注意:我最好不要使用CSS宽度,因为我认为这不是最佳实践。 This easily breaks if a desktop user clicks the link using split screen or a resized window. 如果桌面用户使用拆分屏幕或调整大小的窗口单击链接,则很容易中断。

The issue with using CSS media queries for this is that if the user do not have the app installed, it won't do anything (or in case of Android, it redirects the user to the app on the Play Store). 为此使用CSS媒体查询的问题是,如果用户未安装该应用程序,则它将不会执行任何操作(或者,对于Android,它将用户重定向到Play商店中的应用程序)。

Hence my advice is to use Javascript, check the userAgent string, and set the links through that. 因此,我的建议是使用Javascript,检查userAgent字符串,并通过它设置链接。 Use a timeout delay or a timer to check to see if the user is still on the page after they clicked the link. 使用超时延迟或计时器检查用户单击链接后是否仍在页面上。 If they are, that means they don't have the app installed, hence you can then redirect them to the regular page. 如果是这样,则意味着它们没有安装应用程序,因此您可以将它们重定向到常规页面。

For examples or gists, see the following: 有关示例或要点,请参见以下内容:

How i can make crossbrowser native-app urls with http url fallback on website? 如何在网站上使用http url后备使跨浏览器的本机应用url?

How to launch apps (facebook/twitter/etc) from mobile browser but fall back to hyperlink if the app isn't installed 如何从移动浏览器启动应用程序(facebook / twitter / etc),但是如果未安装应用程序,则退回到超链接

https://webmasters.stackexchange.com/questions/47161/app-uri-scheme-fallback-urls https://webmasters.stackexchange.com/questions/47161/app-uri-scheme-fallback-urls

You can use bootstrap Responsive-utilities class to achieve this: 您可以使用bootstrap Responsive-utilities类来实现此目的:

http://getbootstrap.com/css/#responsive-utilities http://getbootstrap.com/css/#sensitive-utilities

<a class="visible-xs" href="fb://profile/6815841748">Facebook</a>
<a class="visible-xs"  href="instagram://user?username=barackobama">Instagram</a>
<a class="visible-xs" href="twitter://813286">Twitter</a>

Web 网页

<a class="hidden-xs" href="https://www.facebook.com/6815841748">Facebook</a>
<a class="hidden-xs" href="https://www.instagram.com/barackobama">Instagram</a>
<a class="hidden-xs" href="https://www.twitter.com/813286">Twitter</a>

It can be done with css 可以用css完成

Mobile 移动

<a class="mobile" href="fb://profile/6815841748">Facebook</a>
<a class="mobile" href="instagram://user?username=barackobama">Instagram</a>
<a class="mobile" href="twitter://813286">Twitter</a>

Web 网页

<a class="web" href="https://www.facebook.com/6815841748">Facebook</a>
<a class="web" href="https://www.instagram.com/barackobama">Instagram</a>
<a class="web" href="https://www.twitter.com/813286">Twitter</a>

CSS 的CSS

.mobile{
  display:none;
}

@media only screen and (max-width: 1024px) {
  .mobile{
    display:block;
  }
  .web{
    display:none;
  }
}

Make sure you put both set of hyperlinks on the webpage. 确保在网页上都放置了两组超链接。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在移动网站上创建“桌面版本”链接而不将其重定向到移动网站 - How to create a “Desktop Version” link on mobile website without it redirecting to the mobile site 如何使用移动设备和桌面的媒体查询? - How to use media queries for mobile devices and desktop? 如何在移动网站上创建“查看桌面版本”链接,而在解析后又不会循环回到移动版本? - How can I create a “view to desktop version” link on mobile site without it looping back to mobile version when it resolves? 如何在中预览移动网站 <iframe> 在引导模式下站点的桌面版本中 - How to preview mobile site in <iframe> in desktop version of site in bootstrap modal 通过更改链接中的URL链接到Wordpress移动网站中的确切页面 - Link to exact page in Wordpress mobile site by changing url in link 创建链接以在台式机的URL上打开移动应用程序 - create link to open app for mobile on URL for desktops 如何使用在桌面浏览器上运行的移动应用程序渲染移动屏幕? - How to render a mobile screen with mobile app running on desktop browser? 如何强制桌面浏览器使用专为移动设备设计的媒体查询? - How to force desktop browser to use media queries designed for mobile? 从移动网站重定向到桌面网站 - Redirect from mobile site to desktop site 从移动设备(wordpress)重定向后,如何留在桌面版网站上 - How to stay on Desktop site when redirected from mobile (wordpress)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM