Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome only error: Failed to execute 'scroll' on 'Window': No function was found that matched the signature provided

I'm getting this error in Chrome only (it works in Safari/Firefox):
Failed to execute 'scroll' on 'Window': No function was found that matched the signature provided. The code is inside an inline event:

<div onclick='function scrollToByIntoView () {
    window.scroll({
      top: 0, 
      left: 0, 
      behavior: "smooth"
    })
  };
scrollToByIntoView();'>

I can't understand what's the problem.
PS: Note that this code is the output I get after DOM rendering. The actual code is splitter in different components/functions that I use in my server side templating engine, as, as noted in comments below, mixing this code directly should be avoided.

like image 464
Paulo Janeiro Avatar asked Feb 01 '17 10:02

Paulo Janeiro


People also ask

What is window scrollTo?

Definition and Usage The scrollTo() method scrolls the document to specified coordinates.

How do you scroll in JavaScript?

To scroll the page with JavaScript, its DOM must be fully built. For instance, if we try to scroll the page with a script in <head> , it won't work. Regular elements can be scrolled by changing scrollTop/scrollLeft . We can do the same for the page using document.

How do I scroll down on Windows?

If you look to the right side of your keyboard, you'll see four arrows: up, down, left, and right. You can use the down arrow to scroll down on a web page and the up arrow to scroll back up.


1 Answers

Perhaps try scrollTo. This is cross browser supported for x and y coordinates.

http://www.w3schools.com/jsref/met_win_scrollto.asp

<div onclick="window.scrollTo(0,0)">...</div>
like image 135
Daisuke Tahara Avatar answered Sep 18 '22 14:09

Daisuke Tahara