repeatedly toggle iframe scrollbar in javascript -
to ward off closing, yes have looked @ of related questions. here related questions not duplicates, share same title: scrollbar iframe in javascript , toggle iframe scrolling in javascript? unable make solutions suggested there work. lets begin
hi, need toggle scrollbar on iframe content changes. have code thought work, fails. code below http://jsfiddle.net/3nnaf/2
to demo concept, i'm trying iframe scrollbar turn on , off in loop
html:
<iframe src="www.google.com" id="iframe" seamless scrolling="no" ></iframe>
attempt using 'scrolling' attribute:
(function toggleiframe(){ var togglescroll = document.getelementbyid('iframe').scrolling == 'no'; if (togglescroll){ document.getelementbyid('iframe').scrolling = 'yes'; }else{ document.getelementbyid('iframe').scrolling = 'no'; } settimeout(toggleiframe, 2000); }());
attempt using styling
(function toggleiframe(){ var togglescroll = document.getelementbyid('iframe').style.overflowy == 'scroll'; if (togglescroll){ document.getelementbyid('iframe').style.overflowy = 'hidden'; }else{ document.getelementbyid('iframe').style.overflowy = 'scroll'; } settimeout(toggleiframe, 2000); }());
is possible turn iframe scoll bars on , off repeatedly?
thanks, user117...
your issue here:
<iframe src="www.google.com" id="iframe" seamless scrolling="no" ></iframe>
the same origin policy prevents interacting page domain.
edit
ohh.. i'm bad, i'm bad.
settimeout(toggleiframe(), 2000);
the function called:
(your error console have told that, btw.)
edit 2 ok, did run code , make changes it.
you had 3 major issues kept code running propertly.
- on chrome, @ least, same origin policy kept google loading in iframe. thus, nothing ran.
- you did have wrong method of
settimeout
onsettimeout
. see fixed in edit. - you using
toggleiframe()
insettimeout
invocation. see you've caught 1 too.
this code correctly toggle overflowy between 'hidden'
, ''
(function toggleiframe2(){ var iframe = document.getelementbyid('iframe'); console.log("starting value" + iframe.style.overflowy ); var oldvalue = iframe.style.overflowy; function inner() { var togglescroll = (iframe.style.overflowy === 'hidden'); var newvalue = togglescroll ? oldvalue : 'hidden' console.log(newvalue); iframe.style.overflowy = newvalue; settimeout(inner, 2000); } inner(); }());
at point, newvalue correctly being toggled -- isn't yielding desired effect. i'll admit that.
with major show stoppers in code resolved, perhaps 1 of answers on toggling scroll bars work now.
Comments
Post a Comment