HTML viewer

Discussions about the BBC BASIC language, with particular reference to BB4W and BBCSDL
Bad_Wolf
Posts: 19
Joined: Thu 05 Jul 2018, 06:00

HTML viewer

Post by Bad_Wolf »

Hi everyone,

I need some help writing an application for BBC4W/BBCSDL. I am coming from Xojo, which is an OOP visual development tool.

In my Xojo applications, I use an HTML viewer object to show results in a formatted way. That HTML viewer object uses a browser to display its data. It has used Internet Explorer for a long time. However, since the inclusion of Edge with Windows, it uses the Edge Browser on Windows. But to simplify things, let us say it uses the system browser.

Now, I want to create applications with BB4W/BBCSDL. I like to show the results of those applications inside an HTML (browser) window. I have no idea to create my own HTML window in BBC Basic.

Please, can you tell me if there is a way I can create such an HTML browser window myself and if yes, how? Can I send the HTML created inside my BBC basic application to a browser (Firefox or Chrome), and how this is done?

Thank you so much for your help, which I appreciate.

Wish you all a great weekend!

Chris
Hated Moron

Re: HTML viewer

Post by Hated Moron »

Bad_Wolf wrote: Sat 14 Oct 2023, 12:24 Please, can you tell me if there is a way I can create such an HTML browser window myself and if yes, how?
Are you happy to spawn an 'external' browser (i.e. a different process) or does it need to be a window that you own, for example so that you can resize or move it etc.?

If it has to be an 'owned' window I only know how to do that in BBC BASIC for Windows, I've not investigated how it might be achieved in BBC BASIC for SDL 2.0.

If it's OK to spawn an external browser, then you can do that in a platform independent way (at least, for desktop platforms) using this code, which I've lifted from SDLIDE.bbc:

Code: Select all

      DEF PROCopenurl(url$)
      IF INKEY$(-256) = "W" THEN
        SYS "ShellExecute", @hwnd%, "open", url$, 0, 0, 1
      ELSE
        CASE @platform% AND &F OF
          WHEN 0:
            SYS "WinExec", "cmd /cstart " + url$ + "&", 0
          WHEN 1:
            SYS "system", "xdg-open " + url$ + "&"
          WHEN 2:
            SYS "system", "open " + url$ + "&"
        ENDCASE
      ENDIF
      ENDPROC
To open a 'local' HTML page you'll need to store it in your local filesystem (for example in @tmp$) and specify a file URI, such as:

Code: Select all

      url$ = "file:///" + @tmp$ + "mypage.html"
Does that help?
Bad_Wolf
Posts: 19
Joined: Thu 05 Jul 2018, 06:00

Re: HTML viewer

Post by Bad_Wolf »

Hello,

Thank you so much for your help and advice. My applications should "own" the window because its size should be dependant on the data it has to show.

I will try out your solution tomorrow.

Thank you again, I really appreciate your help.

Have a great day!

Kind Regards,

Chris
Bad_Wolf
Posts: 19
Joined: Thu 05 Jul 2018, 06:00

Re: HTML viewer

Post by Bad_Wolf »

Hello again,

I just tried out your code, and it worked very well. I used BBC for Windows and everything worked out perfectly. I could view a URL but also a local HTML file.

It would be nice if you could show me the code and how I can create an owned solution where I can control the window position and size. However, when it is impossible, I will use the method you already gave me.

Thank you so much for your help which I appreciate. I really searched the Internet but could not find anything. You surely made my day!

Kind Regards,

Chris
Hated Moron

Re: HTML viewer

Post by Hated Moron »

Bad_Wolf wrote: Sat 14 Oct 2023, 19:33 It would be nice if you could show me the code and how I can create an owned solution where I can control the window position and size. However, when it is impossible, I will use the method you already gave me.
If you're keen for it to be a cross-platform solution, have you considered using embedded Javascript to change the size and position? You could use the window.resizeTo method to change the size and window.moveTo to set the position.

I'd suggest trying this first before going for a Windows-only solution, anyway.
Bad_Wolf
Posts: 19
Joined: Thu 05 Jul 2018, 06:00

Re: HTML viewer

Post by Bad_Wolf »

Hello,

Thank you again for your reply and advice. I appreciate your thoughts because I didn't think so far. You are correct. It is indeed better to use embedded JavaScript. I have some Javascript knowledge and a few Udemy courses about this subject. So, it is time to collect the necessary knowledge to make that plan work.

When I have the solution, I will share it here.

I wish you a great Sunday and all the best!

Kind regards,

Chris