Is there a system call to open HTML file programatically?

Member
Posts: 321
Joined: 2004.10
Post: #1
Is there a way (like some system call) to simply open up an HTML file
programatically from within an application which the user could read,
and then close off and return to the application from where the HTML
file was invoked?

I've been poking around Apple's documentation but I'm not finding
anything.
Quote this message in a reply
Moderator
Posts: 1,140
Joined: 2005.07
Post: #2
Um, fopen/scanf?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #3
Er, what? Ask questions in English Rasp
Quote this message in a reply
Moderator
Posts: 592
Joined: 2002.12
Post: #4
This is what I use in my Cocoa code for displaying a HTML file from my program in the default web browser.

Code:
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"http://www.url.co.uk/whatever.html"]];


or this code will open a HTML in the default program for viewing HTML files

Code:
[[NSWorkspace sharedWorkspace] openFile:@"filepath/filename.html"];

However you have to be careful with this as on my computer GoLive is the default application for viewing HTML files opened this way.
Quote this message in a reply
Oldtimer
Posts: 834
Joined: 2002.09
Post: #5
I think you mean that the HTML file is opened in Safari or something, right? You could try issuing a system call with "open path/to/my/file"... I dug around the Cocoa docs for a while, but strangely I couldn't find anything.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #6
in Cocoa, NSWorkspace handles opening files and URLs in other applications, in Carbon LaunchServices does the same. LaunchServices has a couple more features than NSWorkspace, so it may occasionally be necessary to use LS from Cocoa (not that that's hard, given the toll-free bridging of CFString<->NSString and CFURL<->NSURL).
Quote this message in a reply
Member
Posts: 321
Joined: 2004.10
Post: #7
I've got a C++ application. Don't want to use Carbon. Tried just sticking
the [[NSWorkspace sharedWorkspace] openFile:@"filepath/filename.html"];
into it with this header that I got by looking at a Cocoa template project
in Xcode.

#import <Cocoa/Cocoa.h>

I get 9,742 errors which I belive is a record for me Smile

I don't know one iota about objective C. Come to think of it, I don't even know
what an iota is Smile

Is it possible to incorporate this snippet of objective c into a C++ application?
If it is trivial, could someone just post the code. I'm thinking it might be about
a long as a "hello world" program, but then I could be wrong here as well.
Quote this message in a reply
Moderator
Posts: 1,140
Joined: 2005.07
Post: #8
If it's just a file localized on your HDD, I still recommend using fopen and fread.
Quote this message in a reply
Member
Posts: 370
Joined: 2002.04
Post: #9
If you don't want to use Carbon or Cocoa, use Fenris's idea:
Code:
system("open /path/to/myfile.html");

Did you ever wonder why we had to run for shelter when the promise of a brave new world unfurled beneath the clear blue sky?
Quote this message in a reply
Moderator
Posts: 592
Joined: 2002.12
Post: #10
akb825 Wrote:If it's just a file localized on your HDD, I still recommend using fopen and fread.

Using this method you would need to have something in your application for rendering the HTML.

I think what he is asking for is a method to allow an external application designed for the purpose to do it.
Quote this message in a reply
Moderator
Posts: 1,140
Joined: 2005.07
Post: #11
I thought he was asking how to just show the code. I'm wondering if there's a class that just takes text and renders the HTML, though. (since I know there are HTML classes in Carbon and Cocoa)
Quote this message in a reply
Member
Posts: 321
Joined: 2004.10
Post: #12
Bingo. "...Renders the HTML" That's what I should of said.
Quote this message in a reply
Member
Posts: 370
Joined: 2002.04
Post: #13
WebKit might be the way to go...

Did you ever wonder why we had to run for shelter when the promise of a brave new world unfurled beneath the clear blue sky?
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  how to call fathers setNeedsDisplay from child. iluzone 5 6,310 Dec 7, 2006 04:11 AM
Last Post: iluzone
  Call For Help: The Game Track Open Source Project jolivierld 2 2,672 Aug 30, 2005 03:48 AM
Last Post: jolivierld