1

So i have an i frame

<iframe onload='window.top.scrollTo(0,0);' scrolling='no' src='http://link.me/en/' />

and on this iframe i would like to ad also

<iframe onload='resizeIframe(this)' scrolling='no' src='http://link.me/en/' />

I have tried:

<iframe onload='window.top.scrollTo(0,0);resizeIframe(this)' scrolling='no' src='http://link.me/en/' />

but is not working.

How can i combine

onload='resizeIframe(this)' and onload='window.top.scrollTo(0,0);' in the same i frame?

Thank you

John Grischam
  • 224
  • 1
  • 19

2 Answers2

0

Define a function for the onLoad event and do all of your work in there.

<script>
    function onIframeLoad(el) {
        resizeIframe(el);
        window.scrollTo(0,0);
    }
</script>
<iframe onload='onIframeLoad(this)' scrolling='no' src='http://link.me/en/' />
tt9
  • 5,784
  • 6
  • 42
  • 65
0

Problem: exception is thrown before resizeIframe is executed (probably by window.top.scrollTo(0,0))

<iframe onload='console.log("xx"); window.top.scrollTo(0,0); console.log("yy"); console.log("zz")' scrolling='no' src='https://en.wikipedia.org/wiki/Page' />

Below is example with no problem

<iframe onload='console.log("xx"); console.log("yy"); console.log("zz")' scrolling='no' src='https://en.wikipedia.org/wiki/Page' />
Kamil Kiełczewski
  • 85,173
  • 29
  • 368
  • 345
  • Hi Kamil! I'm doing this onload='console.log("window.top.scrollTo(0,0)"); console.log("resizeIframe(this)")' but is not working. What am i doing wrong? – John Grischam Jan 29 '19 at 19:22
  • I copy your code and it works (two lines in console appears), however when you type `'console.log("window.top.scrollTo(0,0)")` you will only see text on console, the scroll will be not executed . If our page is on the same domain, for scroll you can try this solution https://stackoverflow.com/a/1229832/860099: `onload="resizeIframe(this); this.contentWindow.document.documentElement.scrollTop=0; "` – Kamil Kiełczewski Jan 29 '19 at 19:27
  • 1
    @JohnGrischam so if in your case the instruction `window.top.scrollTo(0,0)` raise exception - then currently the best choice is to drop it. – Kamil Kiełczewski Jan 29 '19 at 19:42