1. Hannu Pikkarainen
  2. PowerBuilder
  3. Tuesday, 6 August 2019 07:49 AM UTC

Hi,

In my Power Builder application I need to open url in Chrome browser even though it is not set as default browser. Any suggestions how to do it?

BR, Hannu Pikkarainen

 

 

Tobias Roth Accepted Answer Pending Moderation
  1. Monday, 25 January 2021 18:45 PM UTC
  2. PowerBuilder
  3. # 1

Hi Hannu,

i attached a nvo browsercontrol, that we use to open links and check installed browsers.

I hope this will help :)

forward
global type n_browsercontrol from nonvisualobject
end type
end forward

global type n_browsercontrol from nonvisualobject autoinstantiate
end type

type prototypes
Function long ShellExecute( long hwnd,  string lpOperation, string lpFile, string lpParameters,  string lpDirectory,  integer nShowCmd) Library "shell32.dll" alias for "ShellExecuteW" 
end prototypes

type variables
Public:
Constant String is_browser_default = "default"
Constant String is_browser_chrome = "chrome"
Constant String is_browser_firefox = "firefox"
Constant String is_browser_edge = "edge"
Constant String is_browser_internetexplorer = "iexplore"
end variables

forward prototypes
public subroutine of_open_link (string as_url, string as_browser)
private function window of_get_parentwindow ()
public function boolean of_is_browser_installed (string as_browser)
end prototypes

public subroutine of_open_link (string as_url, string as_browser);// Arguments:	
// as_url			URL to open
// as_browser	is_browser_default, is_browser_chrome, is_browser_firefox, is_browser_edge or is_browser_internetexplorer
//
// Example: ln_browsercontrol.of_open_link("http://www.google.de",ln_browsercontrol.is_browser_chrome)
string 	ls_null, ls_exe
setnull(ls_null)

choose case as_browser
	case is_browser_default
		ShellExecute( Handle(of_get_parentwindow()), 'Open', as_url, ls_null, "", 1)
	case is_browser_chrome, is_browser_firefox, is_browser_internetexplorer
		RegistryGet("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\"+as_browser+".exe","", RegString!, ls_exe)
		if not isnull(ls_exe) and ls_exe <> "" then
			if fileexists(ls_exe) then
				run(ls_exe+" "+ as_url)
			end if
		end if
	case is_browser_edge
		ShellExecute( Handle(of_get_parentwindow()), 'Open', "microsoft-edge:"+as_url, ls_null, "", 1)
end choose
end subroutine

private function window of_get_parentwindow ();
POWEROBJECT parent_obj 

parent_obj = this.GetParent() 
DO WHILE IsValid (parent_obj) 
	IF parent_obj.TypeOf() <> Window! THEN 
		parent_obj = parent_obj.GetParent() 
	ELSE 
		EXIT 
	END IF 
LOOP 

if isValid( parent_obj ) = false then
	SetNull( parent_obj )
end if

return parent_obj
end function

public function boolean of_is_browser_installed (string as_browser);// Arguments:	
// as_browser	 is_browser_chrome, is_browser_firefox or is_browser_internetexplorer
//
// Example: ln_browsercontrol.of_browser_exists(ln_browsercontrol.is_browser_chrome)

boolean 	lb_exists
string		ls_exe

choose case as_browser
	case is_browser_chrome, is_browser_firefox, is_browser_internetexplorer
		RegistryGet("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\"+as_browser+".exe","", RegString!, ls_exe)
		if not isnull(ls_exe) and ls_exe <> "" then
			if fileexists(ls_exe) then
				lb_exists = true
			end if
		end if
end choose

return lb_exists
end function

on n_browsercontrol.create
call super::create
TriggerEvent( this, "constructor" )
end on

on n_browsercontrol.destroy
TriggerEvent( this, "destructor" )
call super::destroy
end on

Regard,

Tobi

Attachments (1)
Comment
There are no comments made yet.
Samir Kothari Accepted Answer Pending Moderation
  1. Monday, 25 January 2021 14:22 PM UTC
  2. PowerBuilder
  3. # 2

Hello, curious if you found any other solution for powerbuilder 2017 aside from changing the registry?

 

 

Comment
There are no comments made yet.
René Ullrich Accepted Answer Pending Moderation
  1. Tuesday, 6 August 2019 07:55 AM UTC
  2. PowerBuilder
  3. # 3

Hi Hannu,

you can start the chrome browser and pass the url as command line parameter.

e.g. run ("chrome.exe https://community.appeon.com/")

(Maybe you have to specify also the path to chrome.exe)

 

Comment
  1. Samir Kothari
  2. Monday, 25 January 2021 14:14 PM UTC
Hello, I tried that (powerbuilder 2017 R3) using Microsoft Edge (default browser), but unfortunately internet explorer 11 still opens up
  1. Helpful 1
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.