Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: 对象不支持此操作 (object does not support this operation) #25

Closed
albertwoo opened this issue Jul 20, 2019 · 7 comments

Comments

@albertwoo
Copy link

Description

Navigation.newUrl does not work on IE11. I got error says object does dot support this operation.

Below code can be a workaround for me:

  let goToUrl url =
    Browser.Dom.window.history.pushState((), "", url)
    let evt = Browser.Dom.document.createEvent("Event")
    evt.initEvent("NavigatedEvent", false, false)
    Browser.Dom.window.dispatchEvent evt |> ignore
    Cmd.none

Expected and actual results

Should work on IE 11

Related information

  • elmish version: 3.0.1
  • fable-compiler version: 2.3.12
  • fable-core version: 3.0
  • Operating system: windows 10
@MangelMaxime
Copy link
Member

This seems to be a limitation of IE11 indeed Source can I use

Did you try to configure babel to support IE11 too? Doc

I think if configured correctly babel will convert the code to IE11 compatible code.

@albertwoo
Copy link
Author

Will try that in the future. Thanks to pint this out.

@SCullman
Copy link

As I just run into the same issue: IE11 requires now a polyfill for CustomEvent.
(Added because information was kind of hidden in links)

@kspeakman
Copy link

kspeakman commented Jan 6, 2020

@MangelMaxime Babel will not polyfill CustomEvent. It depends on core-js for polyfill, which has decided not to polyfill it (see here). So because of the change made to Elmish Browser (I believe here ), Navigate.newUrl will not be compatible with IE11 unless a separate polyfill is also imported.

cc @et1975

@et1975
Copy link
Member

et1975 commented Jan 6, 2020

@kspeakman thanks for pointing this out, could you recommend a package that polyfills CustomEvent?

@kspeakman
Copy link

Here's what I did.

npm install --save custom-event-polyfill

Then before Program.mk{...}.

Fable.Core.JsInterop.importAll "custom-event-polyfill/polyfill.js"

@albertwoo
Copy link
Author

@et1975 you can also just copy the function from below link and paste it to your index.html in script block:
https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent#Polyfill

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants