Js_of_ocaml: How to access browser history?


#1

I’m trying to access the history API pushState method. Here’s what I have so far:

let push url =
    let h = Dom_html.window##history in
    h##pushState(Js.null, Js.string url, Js.null)

Dom_html.window##history doesn’t typecheck:

This expression has type
         Dom_html.history Js.t Js.readonly_prop =
           < get : Dom_html.history Js.t > Js.gen_prop
       but an expression was expected of type 'a Js.meth

What is the correct way?


#2

Well, figured it out. Attribute access needs a dot, and method invocation syntax was wrong. This works:

let push url =
    let url' = Js.string url in
    Dom_html.window##.history##pushState Js.null url' Js.null