javascript 在浏览器或本机应用程序中正确打开 Facebook 页面链接 IOScordova
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23802455/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Open facebook page link in browser or native app correctly IOS cordova
提问by AtanuCSE
Previous question on this similar topic isn't working for me and most of them are unanswered.
关于这个类似主题的上一个问题对我不起作用,而且大多数都没有答案。
I want to take the user to a facebook page with button click. Updated facebook is installed in iphone, latest cordova is installed, inappbrowser plugin is used. Now my code is
我想通过单击按钮将用户带到 Facebook 页面。iphone 中安装了更新的facebook,安装了最新的cordova,使用了inappbrowser 插件。现在我的代码是
window.open('https://www.facebook.com/latechnologies', '_system','location=yes');
This works perfectly on android. But in IOS link is catched by nation facebook app and take me to the facebook wall of the use not the page feed. That means it just open the native app,but don't take to any page.
这在android上完美运行。但是在 IOS 中链接被国家 facebook 应用程序捕获并带我到使用的 facebook 墙而不是页面提要。这意味着它只是打开本机应用程序,但不进入任何页面。
Then I searched, and tried some suggestions
然后我搜索,并尝试了一些建议
window.open('fb://facebook.com/latechnologies', '_system','location=yes');
window.open('fb://pages/latechnologies', '_system','location=yes');
window.open('fb://pages', '_system','location=yes');
None of them are working. Every time it takes to the user wall. How can I simply take the user to the facebook page? Native app or browser doesn't matter. Just want to take the user to the page.....................
他们都没有工作。每次都要到用户墙。我怎样才能简单地将用户带到 Facebook 页面?本机应用程序或浏览器无关紧要。只是想把用户带到页面........................
回答by jonas
For me using the Facebook page id instead of the page name works fine, e.g.
对我来说,使用 Facebook 页面 ID 而不是页面名称可以正常工作,例如
window.open('https://www.facebook.com/1401408870089080', '_system');
回答by Michael
I know this is old but I had this problem too, and the accepted answer is through the browser, not through the FB app.
我知道这是旧的,但我也有这个问题,接受的答案是通过浏览器,而不是通过 FB 应用程序。
Answer = fb://profile/12323435435
答案 = fb://profile/12323435435
On IOS pages are under 'profile'
在 IOS 页面上位于“个人资料”下
fb://profile/ - FOR IOS
fb://page/ - FOR ANDROID
<a onclick="window.open('fb://profile/INSERT_FB_ID_HERE','_system')">
Your text or button here </a>
You can find a FB profile or page here : https://findmyfbid.com
您可以在此处找到 FB 个人资料或页面:https: //findmyfbid.com
回答by Mohammad Nurdin
Open up your MainViewController.m file.
打开您的 MainViewController.m 文件。
Insert this code after @implementation and before @end MainViewController.
在@implementation 之后和@end MainViewController 之前插入此代码。
- (BOOL) webView:(UIWebView*)theWebView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
{
NSURL *url = [request URL];
// Intercept the external http requests and forward to Safari.app
// Otherwise forward to the PhoneGap WebView
if ([[url scheme] isEqualToString:@"http"] || [[url scheme] isEqualToString:@"https"]){
[[UIApplication sharedApplication] openURL:url];
return NO;
}
else {
return [super webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType];
}
}
回答by Carlos Galeano
You need to install a plugin to open Apps: org.apache.cordova.inappbrowser 0.5.4 "InAppBrowser"
您需要安装一个插件才能打开应用程序:org.apache.cordova.inappbrowser 0.5.4 "InAppBrowser"
After that you must to know what is the Facebook Page Id, for this: https://graph.facebook.com/latechnologies
之后,您必须知道 Facebook 页面 ID 是什么,为此:https: //graph.facebook.com/latechnologies
Take the ID number and replace the username of the Fanpage: https://www.facebook.com/1382616721988023
取身号,替换粉丝专页的用户名:https: //www.facebook.com/1382616721988023
In that's all... ;)
仅此而已...;)
Like Jonas's Answer! Different method! :)
就像乔纳斯的回答一样!不同的方法!:)
回答by Aneesh
After trying a few iterations and few of the suggestions above, the following code worked for me. window.open('fb://pages/, '_system');
在尝试了几次迭代和上面的一些建议之后,下面的代码对我有用。window.open('fb://pages/, '_system');
The above is intended to open the page on facebook app (if it is installed).
以上是为了在 facebook 应用程序上打开页面(如果已安装)。
Ofcourse, I have installed cordova inappbrowser plugin.
当然,我已经在appbrowser插件中安装了cordova。