I have a Delphi program that creates HTML files. Later when a button is pressed a TWebBrowser is created and a WebBrowser.Navigate causes the html page to display.
Is there anyway to set the WebBrowser “default directory” so it will always be the location of the Delphi executable not the HTML file?
I do not want to set the Base value in the HTML to a hardcoded value because then when the HTML is ran from another Delphi exe they are not found.
for example:
if the exe is run from D:\data\delphi\pgm.exe then the base location D:\data\delphi\ and the jpgs are at D:\data\delphi\jpgs\
but if the exe is run from: C:\stuff\pgm.exe i want the base location to be C:\stuff\ and the jpgs to be at C:\stuff\jpgs\
So I cannot write a line in the HTML with the base location since when it is ran from another exe it would point to wrong location for that exe.
So I either need to set the base location when I create the webbrowser and before I read the HTML or I need a way to pass into the webbrowser the location where I can then set the base location.
Sorry for being so long-winded but I could not figure out how to saw what I needed.
Since TWebBrowser is just a wrapper around the Internet Explorer engine, there is an alternative you can try if you allow client-side scripting to be enabled in your browser.
app that implements the
IDispatchinterface, and give it a string
property that returns the app’s
current running path.
implements the
IDocHostUIHandlerinterface, and override its
GetExternal()method to return a pointer to your
object from #1.
ICustomDocinterface, and pass your
IDocHostUIHandlerobject to its
SetUIHandler()method.Refer to MSDN for more details:
http://msdn.microsoft.com/en-us/library/aa770041.aspx
This way, your HTML can contain scripting that can use the
window.externalobject to retreive the app’s path and update its JPG references dynamically, such as in the OnLoad event, ie: