scrollBy doesn't work in Firefox and Opera

半世苍凉 提交于 2019-12-11 06:37:51

问题


This scrollBy function works in Internet Explorer, but ignores by Firefox and Opera. Can anyone help to solve this problem?

function scrollLeft(s){
document.frames['my_iframe'].scrollBy(-s,0);
window.frames['my_iframe'].scrollBy(-s,0);
}

function scrollRight(s){
document.frames['my_iframe'].scrollBy(s,0);
window.frames['my_iframe'].scrollBy(s,0);
}

Here is an example that works in Internet Explorer browser, but doesn't work in Firefox and Opera: http://igproject.ru/iframe-scrolling/index.htm


回答1:


In Firefox, etc. you need to use scrollTo() instead of scrollBy().

See: http://jsfiddle.net/4CkML/

Example:

window.scrollTo(50,50);

You cannot use scrollTo/By if the domains don't match. You can see here that a javascript error is produced:

http://jsfiddle.net/3CbZc/

Permission denied to access property 'scrollTo'

Edit - Updating answer to incorporate answer from long comment chain:

var oIF = document.getElementById('my_iframe').contentWindow; oIF.scrollBy(s, 0);


来源:https://stackoverflow.com/questions/6566037/scrollby-doesnt-work-in-firefox-and-opera

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!