Uses a timer to check what's happening to the url, this is a really simple example but could be developed to do more useful things.
Code: Select all
;-- OS specific
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Windows
#FileSep$ = "\"
CompilerCase #PB_OS_Linux
#FileSep$ = "/"
CompilerCase #PB_OS_MacOS
#FileSep$ = "/"
CompilerEndSelect
;-- Randomise page name
File$ = GetCurrentDirectory() + "tmp" + #FileSep$ + Hex(Date()+ElapsedMilliseconds()) + ".htm"
DefaultURL$ = "file://" + File$
;-- temp file for pages
CreateDirectory("tmp")
html$ = "<html style='overflow: auto;'>"
html$ + "<head>"
;-- Google fonts, cos we can ;-)
html$ + "<link href='http://fonts.googleapis.com/css?family=Alegreya' rel='stylesheet' type='text/css'>"
html$ + "<style type='text/css'>"
html$ + "div {margin:0.5em;}"
html$ + ".title {clear:both;padding-top:2em;font-size:2em;font-family:'Alegreya', serif;}"
html$ + "body {background:#EEEEEE;overflow:auto;}"
html$ + "</style>"
html$ + "<title>Title</title>"
html$ + "</head>"
html$ + "<body>"
html$ + "<div class='title'>Catch and process web page get type urls</div>"
html$ + "<div class='container'>"
html$ + "<div class='title'><a href='" + DefaultURL$ + "?state=foo'>foo</a></div>"
html$ + "<div class='title'><a href='" + DefaultURL$ + "?state=bar'>bar</a></div>"
html$ + "<div class='title'><a href='" + DefaultURL$ + "?state=bazuel'>bazuel</a></div>"
html$ + "</div><div style='clear:both;padding:2em;'> </div></body></html>"
MainWindow = OpenWindow(#PB_Any, 0, 00, 800, 600, "Catch and process web page get type urls", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_ScreenCentered)
If MainWindow
If CreateFile(0, File$)
WriteString(0,html$)
CloseFile(0)
Browser = WebGadget(#PB_Any, 0, 0, 800, 600, DefaultURL$)
;-- 250 mS also acts as hyperlink debounce
AddWindowTimer(MainWindow, 123, 250)
EndIf
EndIf
Repeat
Event = WaitWindowEvent(5)
Type = EventType()
Gadget = EventGadget()
Window = EventWindow()
Menu = EventMenu()
Select Event
Case #PB_Event_Gadget
Case #PB_Event_Menu
Case #PB_Event_Timer
If EventTimer() = 123
;-- Process the state parameter from the url
State$ = GetURLPart(GetGadgetText(Browser), "state")
;-- Check State$ is actually set
If State$ <> ""
;--Reset Browser to avoid multiple hits on the same state
SetGadgetState(Browser, #PB_Web_Back)
;-- Probably do more complex things here, alter html and so forth
Debug State$
EndIf
EndIf
Case #PB_Event_CloseWindow
Break
EndSelect
ForEver
;-- purge temp file
DeleteDirectory("tmp", "*.*", #PB_FileSystem_Recursive)
End
Corrected confusing combined url/file name.