Skip to content

How can i call the external when running in browser? #1071

Answered by soywiz
slkgtr asked this question in Q&A
Discussion options

You must be logged in to vote

Before:

Dyn.global["document"]["location"] = "https://google.com/"

After this PR you can also run JS code:
#1086

You will be able to do in the commonMain sourceset:

// alterntaively: Platform.isJs
if (JSEval.available) {
  JSEval("window.location = url;", "url" to "https://www.google.com/")
}

In the meantime, you can just use the expect/actual approach. You create an expect function in the commonMain sourceset, and then implement it in the JS source set, and create a dummy implementation on the other targets/source sets.

You can read more about it here: https://kotlinlang.org/docs/multiplatform-connect-to-apis.html

You can also check the PR #1086 to see how it was implemented, since it sh…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by soywiz
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