Launch webpage in Edge or Safari

  1. 6 months ago

    Craig G

    Dec 29 Australia

    When I use f.launch to open a html file I want it to specifically open in Edge/Internet Explorer or Safari on Mac systems.
    Is there a way to do this rather than the default browser?
    The page doesn't render correctly in Google Chrome.

  2. Tim P

    Dec 29 Pre-Release Testers Rochester, NY

    FolderItem.Launch will automatically use the default application for the item. To use a specific application you will need to use a declare. I know I've shared the one for macOS here on the forum somewhere, but I don't have the Windows equivalent available.

    I don't understand why this post is so hard to find. I've just spent 30 minutes looking for it and I wrote it.

  3. Tim P

    Dec 29 Pre-Release Testers Rochester, NY

    Recovered it from the Answers source

    // Launch help with selected preview browser
    declare function NSClassFromString lib "Foundation" (name as CFStringRef) as Ptr
    declare function sharedApplication lib "AppKit" selector "sharedWorkspace" (obj As Ptr) as Ptr
    dim sharedWorkspace as Ptr = sharedApplication(NSClassFromString("NSWorkspace"))
    
    declare function openFile lib "AppKit" selector "openFile:withApplication:" (id as ptr, urlString as CFStringRef, appName as CFStringRef) as Boolean
    call openFile(sharedWorkspace, TargetFolderItem.NativePath, "Safari.app")
  4. Tim P

    Dec 29 Pre-Release Testers Rochester, NY

    Also available with MBS: https://www.monkeybreadsoftware.net/cocoa-nsworkspacembs-shared-method2.shtml#15

    call NSWorkspaceMBS.openFile(TargetFolderItem, "Safari.app", true)
  5. Michael D

    Dec 30 Pre-Release Testers, Xojo Pro

    Some code I wrote long ago:

    Public Sub ShowURLusingNativeBrowser(url as string)
      ' opens a URL in Safari (mac) or IE (win32) even if user has another browser installed
      dim sh as new shell
      
      #if TargetWin32
        dim cmd as string= """%ProgramFiles%\Internet Explorer\iexplore.exe"" -new " + url
      #elseif TargetMacOS
        dim cmd as string = "osascript -e 'tell application ""Safari"" to open location """ + url + """" + " ' "
      #endif
      
      sh.Execute cmd
      dim result as string = sh.Result
      
    End Sub

or Sign Up to reply!