Comments (8)
I've found it using js.Global.Get("document").Get("readyState")
. But it is always has loading
state( Could give an example how can I run eg println("ready!")
after DOM is loaded?
from go-js-dom.
What does it print if you do this?
var document = dom.GetWindow().Document().(dom.HTMLDocument)
func main() {
document.AddEventListener("DOMContentLoaded", false, func(_ dom.Event) {
println(js.Global.Get("document").Get("readyState"))
})
}
from go-js-dom.
The output is interactive
.
from go-js-dom.
The first thing what I did is include compiled main.js file into
<head>
tag. However whatever selector I use (dom.GetWindow().Document().querySelector("...")
) - it returned nil.
That's because the body does not yet exist when the script runs in <head>
. However, if you delay the execution of your code by calling it from the DOMContentLoaded
event listener, then body and its elements should be ready by then, so QuerySelector
should work.
from go-js-dom.
Of course, I know it. But I thought (I don't know why) that the gopherjs compile into the code that start only when dom is ready)) Thank you for explanation and very good example! If readyState
property defined in DOM specification and it is implemented in all (almost) browsers - why not to include it to the package itself?)
from go-js-dom.
If
readyState
property defined in DOM specification and it is implemented in all (almost) browsers - why not to include it to the package itself?)
I don't think there's a reason not to, it's just not done yet (there are a few not yet implemented features, e.g., see dom.go#L950).
I believe that contributions are welcome (@dominikh, correct if wrong), so feel free to make a PR that adds it if you can/want (since there's no CONTRIBUTING.md file that has special contribution guidelines in this repo, making PRs is the default approach). Thanks!
from go-js-dom.
It's already implemented, as HTMLDocument.ReadyState
. HTMLDocument
is an interface, ReadyState
in turn a method.
An example of accessing it:
dom.GetWindow().Document().(dom.HTMLDocument).ReadyState()
Window.Document
returns the Document
interface, because not all uses of DOM have to be in the context of HTML (SVG would be another context, for example). If you know that you're working with HTML, you can type assert to the HTMLDocument
interface.
For documentation on all the types and methods, see http://godoc.org/honnef.co/go/js/dom.
from go-js-dom.
Good!) Thanks you)
from go-js-dom.
Related Issues (20)
- v2: Create with support for both GopherJS and GOOS=js GOARCH=wasm. HOT 14
- "go get -u honnef.co/go/js/dom" fails HOT 2
- go get honnef.co/go/js/dom HOT 1
- DispatchEvent of "Click"/"Change" HOT 1
- HTMLTemplateElement is missing?
- Feature Request: Element.closest()
- Missing: HTMLDialogElement, HTMLSlotElement, HTMLPictureElement HOT 1
- WheelEvent inherits MouseEvent
- Cannot load honnef.co/go/js/dom/v2: no Go source files HOT 1
- feature request: indexeddb interface
- adoptNode is missing "deep" param
- v2 does not compile with go1.14 HOT 2
- v2: CreateTextNode() panics HOT 3
- v2: unable to DrawImage HOT 3
- v2: RequestAnimationFrame callback argument type misleading HOT 1
- Missing `Children` method on `dom.Element`
- Adding event type strings to use with `AddEventListener`
- go install honnef.co/go/js/dom/v2@latest yields an error message: HOT 1
- Add Element.ReplaceChildren HOT 1
- Adding examples to the repository
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-js-dom.