Ask Your Question
0

In base how to open a URL field?

asked 2018-06-14 00:30:10 +0200

EasyTrieve gravatar image

updated 2018-06-15 19:48:44 +0200

If a text field holds a URL string, how can one easily open the link in your browser?

(A similar question is here: https://ask.libreoffice.org/en/question/3632/hyperlink-field-types-in-base/)

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
0

answered 2018-06-14 00:41:46 +0200

EasyTrieve gravatar image

updated 2018-06-15 19:40:24 +0200

Use this method to just hit F9 on the URL to easily open the web page. (I had seen the method for an extra button, but I didn't want another button for this).

Set this as the KeyPressed event for the field:

' --- If F9 key hit then execute the URL (i.e. show the file or web page) -------------'
Sub KeyPressedEvent(oEvent As Object)
  If oEvent.KeyCode =  com.sun.star.awt.Key.F9 Then   'Adjust to suit your taste'

    'Read the text from the file selection (Assuming the field is named 'URL')'
    DIM s AS STRING 
    s = oEvent.Source.Model.Parent.GetByName("URL").Text
    s = convertToUrl(s) 

    'Start the file with the appropriate URL connection'
    DIM oShell  AS OBJECT  
    oShell = createUnoService("com.sun.star.system.SystemShellExecute")

    oShell.execute(s,,0)
  End If
End Sub

Tip: So when the user hovers over the URL field heading they get a tool tip also set the Help text property on the URL Control to something like: 'Hit F9 to open URL in your browser or other appropriate tool'.

edit flag offensive delete link more
0

answered 2018-06-14 00:57:48 +0200

Ratslinger gravatar image

Hello,

I find using a button to be quite effective. With this macro:

Sub GetURL
    oForm = ThisComponent.Drawpage.Forms.getByName("MainForm")
    DocCtl = ThisComponent.getCurrentController()
    oField = oForm.getByName("txtURL")
    oButton = oForm.getByName("Push Button 1")
    CtlView = DocCtl.GetControl(oField)
    oButton.TargetUrl = CtlView.Text
end sub

attached to After record change event of form and on the push button property Action set to Open document/web page you only need a click of the button to open the link. Works well for opening other documents as well.

No need to use Shell.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2018-06-14 00:30:10 +0200

Seen: 27 times

Last updated: 2 days ago