Skip to content

Commit 43b9fc0

Browse files
committed
Minor example update
1 parent ba58cf1 commit 43b9fc0

File tree

1 file changed

+17
-8
lines changed
  • examples/C/public_network_access

1 file changed

+17
-8
lines changed

examples/C/public_network_access/main.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,18 @@ void public_window_events(webui_event_t* e) {
2323

2424
void private_window_events(webui_event_t* e) {
2525
if (e->event_type == WEBUI_EVENT_CONNECTED) {
26+
27+
// Get port of public window
28+
size_t port = webui_get_port(public_window);
29+
2630
// Get URL of public window
27-
const char* public_win_url = webui_get_url(public_window);
31+
const char* url = webui_get_url(public_window);
32+
33+
// JavaScript
2834
char javascript[1024];
29-
sprintf(javascript, "document.getElementById('urlSpan').innerHTML = '%s';", public_win_url);
35+
sprintf(javascript, "document.getElementById('urlSpan1').innerHTML = 'http://localhost:%zu';", port);
36+
webui_run(private_window, javascript);
37+
sprintf(javascript, "document.getElementById('urlSpan2').innerHTML = '%s';", url);
3038
webui_run(private_window, javascript);
3139
}
3240
}
@@ -70,13 +78,14 @@ int main() {
7078
" <body>"
7179
" <h1>WebUI - Public Network Access Example</h1>"
7280
" <br>"
73-
" The second public window is configured to be accessible from <br>"
74-
" any device in the public network. <br>"
81+
" The public window is configured to be accessible from <br>"
82+
" any device in the network. <br>"
7583
" <br>"
76-
" Second public window link: <br>"
77-
" <h1 id=\"urlSpan\" style=\"color:#c9913d\">...</h1>"
78-
" Second public window events: <br>"
79-
" <textarea id=\"Logs\" rows=\"4\" cols=\"50\" style=\"width:80%\"></textarea>"
84+
" Public window links: <br>"
85+
" <h1 id=\"urlSpan1\" style=\"color:#c9913d\">...</h1>"
86+
" <h1 id=\"urlSpan2\" style=\"color:#c9913d\">...</h1>"
87+
" Public window events: <br>"
88+
" <textarea id=\"Logs\" rows=\"4\" cols=\"50\" style=\"width:60%\"></textarea>"
8089
" <br>"
8190
" <button id=\"Exit\">Exit</button>"
8291
" </body>"

0 commit comments

Comments
 (0)