B4J Question [ABMaterial] URL parameter after hashtag

yiankos1

Well-Known Member
Licensed User
Longtime User
Hello,

I have this redirect URL:
B4X:
https://localhost:8081/fb/updatepassword/#access_token=eyJhbGciOiJIUzI1NiIsImt&expires_at=1706608981&expires_in=3600&refresh_token=mA8xWwjn&token_type=bearer&type=signup

If i try to get a parameter with this:
B4X:
Log(ws.UpgradeRequest.GetParameter("access_token"))

it does not return anything.

If i edit URL manually and replace # with ? then it does normally return the parameter.

In both cirumstances, page loaded normally.

As i read, # at URL is used in order to cover single page webapps.

So my question is how to get the parameter after the hashtag?

UPDATE: This question has been asked here. How can i use it in B4J?
 
Last edited:
Solution
Hooray!

I just found the solution:

B4X:
Log(ws.EvalWithResult("return window.location.hash",Null).Value)

Returns everything after #

if you want to make a map with every parameter, you can do the following:
B4X:
Private url As String = ws.EvalWithResult("return window.location.hash",Null).Value
    
    If url.ToLowerCase.Contains("#") Then
        Dim hash As String
        hash = url.SubString(url.IndexOf("#") + 1)
        
        Dim result As Map
        result.Initialize
        
        Dim params() As String
        params = Regex.Split("&", hash)
        
        For Each param As String In params
            Dim parts() As String
            parts = Regex.Split("=", param)
            
            If parts.Length = 2 Then...

DonManfred

Expert
Licensed User
Longtime User
ws.UpgradeRequest
try to log all parameters from it.
Check what you can get at all.

Maybe you need to get the URL itself to parse it by yourself.
 
Upvote 0

yiankos1

Well-Known Member
Licensed User
Longtime User
Upvote 0

yiankos1

Well-Known Member
Licensed User
Longtime User
Hooray!

I just found the solution:

B4X:
Log(ws.EvalWithResult("return window.location.hash",Null).Value)

Returns everything after #

if you want to make a map with every parameter, you can do the following:
B4X:
Private url As String = ws.EvalWithResult("return window.location.hash",Null).Value
    
    If url.ToLowerCase.Contains("#") Then
        Dim hash As String
        hash = url.SubString(url.IndexOf("#") + 1)
        
        Dim result As Map
        result.Initialize
        
        Dim params() As String
        params = Regex.Split("&", hash)
        
        For Each param As String In params
            Dim parts() As String
            parts = Regex.Split("=", param)
            
            If parts.Length = 2 Then
                result.Put(parts(0), parts(1))
            End If
        Next
        
        ' Now 'result' contains the key-value pairs from the hash
        Log(result)
    End If
 
Last edited:
Upvote 0
Solution
Top