Menu

Local HTML with images

Fenistil
2013-10-24
2014-04-15
  • Fenistil

    Fenistil - 2013-10-24

    Hi!

    It's not really a programming question, but I can't get to a solution about it. I have a HTML page, directly on the device. (Documents/Help.html). In the Documents folder I have also images (Image.png). What I want is to display the HTML in a webbrowser component with images. I can load the HTML with no problem with this:

    DPFWeb1.LoadFromFile(GetAppFolder+'/Documents/Help.html');
    

    But I can't manage to display the images in it. I've tried the followings:

    <img src="Image.png">
    
    <img src="./Image.png">
    <img src="/Image.png">
    <img src="Documents/Image.png">
    <img src="./Documents/Image.png">
    <img src="/Documents/Image.png">
    
    <img src=".\Image.png">
    <img src="\Image.png">
    <img src="Documents\Image.png">
    <img src=".\Documents\Image.png">
    <img src="\Documents\Image.png">
    

    But these aren't working, I just see an empty square instead of my image. :( I see in other forums it should work, but they used an XCode based App (I don't think it's the problem, the Webbrowser should be the same native one).

    Thanks, greetings

     
  • luca

    luca - 2013-10-25

    You are rigth. There's a problem with relative path.

    This works;
    DPFWeb1.LoadFromFile(GetAppFolder+ 'image1.jpg','image/jpeg','');

    And also This works:

    In the img tag add the real image path (in my case GetAppFolder)
    src="file:///'+ GetAppFolder +'/image1.jpg"

    save into a html file and load it

    DPFWeb1.LoadFromFile(htmlfile,'text/html','utf-8')

     

    Last edit: luca 2013-10-25
  • Fenistil

    Fenistil - 2013-10-25

    So I have to rewrite the whole HTML file on-the-fly to get the images loaded... fantastic :D I'll try it, thanks for the tip!

     
    • luca

      luca - 2013-10-25

      I think you can load a template , build a html string and use LoadFromString

       

      Last edit: luca 2013-10-25
  • Fenistil

    Fenistil - 2013-10-26

    Thanks, the LoadFromString works perfectly!

     
  • Ahb Toplama

    Ahb Toplama - 2014-04-09

    Hi Luca and Fenistil

    Do you have any sample for this topic, please share with us. Thanks

     
  • Fenistil

    Fenistil - 2014-04-09

    Hi!

    I use the followings, and works great:

    The HTML file:

    <img src="###PATH###/Help.png">
    

    And the Delphi code:

    procedure TFrame_Help_iPhone.LoadHelp(Lang: string);
    var s:string;
        sl:TStringList;
    
    begin
      sl:=TStringList.Create;
      sl.LoadFromFile(GetAppFolder+'/Documents/Help.html',TEncoding.UTF8);
      s:=StringReplace(sl.Text,'###PATH###','file:///'+GetAppFolder+'/Documents',[rfReplaceAll,rfIgnoreCase]);
      Web1.LoadFromString(s);
    end;
    

    Good luck!

    Greetings

     
  • Ahb Toplama

    Ahb Toplama - 2014-04-15

    Hi
    I need your support
    I opened a html file with webbrowser component (UIWebView)
    the html file like
    ...
    Click-1
    Click-1
    ...

    I need click event info/clicked link.
    How can get info when clicked link in html file like "link1.html" clicked.
    Thanks

     

    Last edit: Ahb Toplama 2014-04-15

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.