How to get web server name
I'm completely out of my depth here. I'm trying to find a way for a BBC BASIC program, running in the in-browser edition of BBCSDL, to discover from where bbcsdl.html was downloaded.
For example, it needs to be able to tell whether it was run as https://wasm.bbcbasic.co.uk/bbcsdl.html or https://wasm.bbcbasic.net/bbcsdl.html. I feel that should be possible, but haven't a clue how to achieve it.
The only thing Google has come up with is this StackOverflow post, but I don't know how to apply it.
For example, it needs to be able to tell whether it was run as https://wasm.bbcbasic.co.uk/bbcsdl.html or https://wasm.bbcbasic.net/bbcsdl.html. I feel that should be possible, but haven't a clue how to achieve it.
The only thing Google has come up with is this StackOverflow post, but I don't know how to apply it.
0
Comments
-
But what language is that 'code snippet' written in? It doesn't look like anything I'm familiar with so I don't know how I would call it from C code or from BASIC code.it appears that code snippet retrieves the detail
The easiest language to use would probably be JavaScript, because I can call that from BBC BASIC code quite straightforwardly:SYS "emscripten_run_script", script$
0 -
Actually, since I want to get a string back it would be:Richard_Russell wrote: »SYS "emscripten_run_script", script$
SYS "emscripten_run_script_string", script$ TO host% host$ = $$host%
So if there's a way to get the server name in JavaScript this should do the job nicely. But is there?
0 -
I'm not sure. The title 'How to extract the hostname portion of a URL' would suggest not, since I don't have the full page URL to start with (and if I did the task would be trivial).Does this help?
But the top-rated reply seems to be talking about how to extract the hostname of the current page's URL, which isn't what the questioner is asking for, but is what I need!
The missing link is that I don't know how to write JavaScript code to return the wanted 'property' as a string. Maybe it's as simple as this (that would be nice!) but I'll have to try it to find out:SYS "emscripten_run_script_string", "window.location.hostname" TO host% host$ = $$host%
0 -
It very nearly was! To find the 'window' object the JavaScript code, not surprisingly, needs to be run in the context of the main thread, not the interpreter's thread (Web Worker in JS parlance). Therefore I needed to add a dummy @memhdc% parameter to force BBC BASIC to do a cross-thread SYS call. Then it works, see below.Richard_Russell wrote: »Maybe it's as simple as this (that would be nice!)
Thanks very much for the pointer (and to Darren Storer at the Discussion Group).
1 -
Nice one! Out of curiosity, what does $$var% do (specifically, the double $) ?0
-
NUL-terminated string, used extensively when interfacing with most OSes or code written in C. Much more common than the CR-terminated string ($var%) these days, in my experience.Out of curiosity, what does $$var% do (specifically, the double $) ?
I expect RISC OS uses CR-terminated strings, but if so it's an outlier.0