0

As the title says I cant reach the scrollTop element of <body> inside my <embed>'ed html file. Im trying to implement a scrollTop button on my index page which loads html documents via js.

content.innerHTML = "<embed id='object' onscroll='scrollFunction()' width='100%' height='100%' src='" + documentName + "'></embed>'";

I tried things like document.getElementById("object").body.scrollTop = 0;

The result is obviously an exception in the console or constantly scrollTop = 0 if I let the .body out and log document.getElementById("object").scrollTop (before setting it to 0)

EDIT:

I changed <embed src=></embed> to <object data=></object> and

var object = document.getElementById("object");
var htmlDocument = object.contentDocument;
htmlDocument.body.scrollTop = 0;

The console exception is: Uncaught DOMException: Failed to read the 'contentDocument' property from 'HTMLObjectElement': Blocked a frame with origin "null" from accessing a cross-origin frame. Idk whats goin on

W.Tf
  • 1
  • 1
  • You need to access the `document` of the page displayed inside the object element first of all. https://stackoverflow.com/a/28754598/10283047 – misorude Jan 09 '19 at 13:01
  • @misorude I made an EDIT – W.Tf Jan 09 '19 at 13:35
  • Well if the content inside the object is loaded from a different domain, then you of course have no JavaScript access to it at all - keyword Same Origin Policy. – misorude Jan 09 '19 at 13:37
  • @misorude but the embeded document is just in a subfolder.. everything is on my domain – W.Tf Jan 09 '19 at 13:42
  • When did you execute the code you have shown? Did you wait for the document embedded inside the object to finish loading? – misorude Jan 09 '19 at 13:43
  • @misorude No the document finished loading. Im using this as a back to top button on my index sidebar for my embeded page instead of an buttton on every page i embed – W.Tf Jan 09 '19 at 13:48

0 Answers0