Skip to content

How do I get the search params in Korge for JS? #2201

Answered by Kietyo
Kietyo asked this question in Q&A
Discussion options

You must be logged in to vote

In your common source directory, you can define a function like this:

expect fun getUrlSearchParams(): String

Then you can implement target specific implementations.

jvm:

// XenoTactic-GameLogic/src/jvmMain/kotlin/com.xenotactic.gamelogic/utils/utils.jvm.kt
actual fun getUrlSearchParams(): String {
    return ""
}

js:

// XenoTactic-GameLogic/src/jsMain/kotlin/com.xenotactic.gamelogic/utils/utils.js.kt
import kotlinx.browser.window

actual fun getUrlSearchParams(): String {
    return window.location.search
}

You can use this function to get the url search params, here's an example of what it looks like in the console:

Replies: 2 comments

Comment options

Kietyo
Mar 21, 2024
Maintainer Author

You must be logged in to vote
0 replies
Answer selected by Kietyo
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants