通过可可应用程序在Safari浏览器中打开网址 [英] Open url in safari through cocoa app

查看:326
本文介绍了通过可可应用程序在Safari浏览器中打开网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过我在Safari中的应用程序在Cocoa中打开一个URL。我使用:

I want to open a URL in Cocoa through my app in Safari only. I am using:

[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString: @"my url"]];

但问题是,如果我的默认浏览器不是Safari,浏览器。但我希望我的网址只在Safari中打开。

But the problem is that if my default browser is not Safari, then the URL gets open in some other browser. But I want my URL to open in Safari only. Please tell the solution.

感谢:)

推荐答案

code>脚本桥使用safari在safari中打开URL,您会在文件 Safari.h 中找到打开URL的方法。
要了解有关使用脚本桥的更多信息,请参阅链接,并使用safari的脚本桥并生成 Safari.h ,请在此处参阅我的回答

Use scripting bridge with safari to open a URL in safari, You will find a method to open url in the file Safari.h. To know more about using Scripting bridge refer the link and to use scripting bridge with safari and generate Safari.h, refer my answer here.

打开Safari中的网址是:

The method to open a URL in Safari is:

NSDictionary *theProperties = [NSDictionary dictionaryWithObject:@"https://www.google.co.in/" forKey:@"URL"];
SafariDocument *doc = [[[sfApp classForScriptingClass:@"document"] alloc] initWithProperties:theProperties];
[[sfApp documents] addObject:doc];
[doc release];

这篇关于通过可可应用程序在Safari浏览器中打开网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆