From 6a65f2a86ba57b77b2d03669fd14e0d9c4c19a86 Mon Sep 17 00:00:00 2001 From: Alexei Anoshenko Date: Fri, 19 Aug 2022 14:28:49 +0300 Subject: [PATCH] Added OpenURL function to the Session interface --- session.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/session.go b/session.go index a85a079..21257b8 100644 --- a/session.go +++ b/session.go @@ -2,6 +2,7 @@ package rui import ( "fmt" + "net/url" "strconv" "strings" ) @@ -69,6 +70,8 @@ type Session interface { DownloadFile(path string) //DownloadFileData downloads (saves) on the client side a file with a specified name and specified content. DownloadFileData(filename string, data []byte) + // OpenURL opens the url in the new browser tab + OpenURL(url string) registerAnimation(props []AnimatedProperty) string @@ -448,3 +451,11 @@ func (session *sessionData) SetTitleColor(color Color) { func (session *sessionData) RemoteAddr() string { return session.brige.remoteAddr() } + +func (session *sessionData) OpenURL(urlStr string) { + if _, err := url.ParseRequestURI(urlStr); err != nil { + ErrorLog(err.Error()) + return + } + session.runScript(`window.open("` + urlStr + `", "_blank");`) +}