0

What am I doing wrong here?

This code works in all other browsers except IE.

I am attempting to auto-fill a form input using the code below.

parent.setTimeout('var input = document.querySelector("form.media-library__upload-url .form-text-input");' +
                      'var nativeInputValueSetter = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, "value").set;    ' +
                      'nativeInputValueSetter.call(input, "http://lorempixel.com/400/200");' +
                      'var ev2 = new Event("input", { bubbles: true});' +
                      'input.dispatchEvent(ev2);', 0);

I have also tried using

setTimeout(function() {
  var input = document.querySelector("form.media-library__upload-url .form-text-input");
  var nativeInputValueSetter = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, "value").set;
  nativeInputValueSetter.call(input, "http://lorempixel.com/400/200");
  var ev2 = new Event("input", {
    bubbles: true
  });
  input.dispatchEvent(ev2);
}, 0);

What is the proper way to do this in IE?

I am constantly getting this error

SCRIPT445: Object doesn't support this action
Barmar
  • 741,623
  • 53
  • 500
  • 612
Bizzet
  • 71
  • 2
  • 12
  • 1
    Which statement is getting the error? – Barmar Feb 25 '18 at 00:48
  • @Barmar I believe it is ''Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, "value").set'' – Bizzet Feb 25 '18 at 00:57
  • Possible duplicate of [Internet Explorer 9, 10 & 11 Event constructor doesn't work](https://stackoverflow.com/questions/26596123/internet-explorer-9-10-11-event-constructor-doesnt-work) – poke Feb 25 '18 at 00:57
  • @JaromandaX I am using version 11.0.16299.15 of Internet Explorer – Bizzet Feb 25 '18 at 01:01
  • The [`Event` constructor](https://developer.mozilla.org/de/docs/Web/API/Event/Event) is not supported in Internet Explorer. In order to create synthetic events, you need to use `document.createEvent` or a polyfill for `CustomEvent` as described in the linked question. – poke Feb 25 '18 at 01:03
  • @Bizzet Which [document mode](https://stackoverflow.com/questions/22034924/how-to-set-ie11-document-mode-to-edge-as-default) is the page loading under? The snippet may work under Standards or Edge mode, but will fail under Compatibility or Enterprise (under these, IE 11 can emulate IE 5.5 - IE 8). – Jonathan Lonowski Feb 25 '18 at 01:03
  • @JonathanLonowski I believe it is something to do with the New Event constructor not being available in IE11. How do I fix this? – Bizzet Feb 25 '18 at 01:40
  • @JaromadaX Do you have any other ideas with this information? – Bizzet Feb 25 '18 at 01:43
  • @Barmar Do you have any other ideas with this information? – Bizzet Feb 25 '18 at 01:43
  • @Bizzet Does this help? "[Internet Explorer 9, 10 & 11 Event constructor doesn't work](https://stackoverflow.com/questions/26596123/internet-explorer-9-10-11-event-constructor-doesnt-work)" – Jonathan Lonowski Feb 25 '18 at 01:51

0 Answers0