/    Sign up×
Community /Pin to ProfileBookmark

Accessing the main scrollbar outside an IFrame?

Hi,

I have an Iframe on a HTML page which contains another web page.

I want to be able to move the main scrollbar which is outside of the Iframe from web page inside the Iframe.

I’m using JavaScript to do this.

I have tried both window.top.scrollto(0,0) and window.scrollto(0,0) but this doesnt work?

I thought that window.top.scrollto(0,0) would work but I get Access Denied JavaScript Error.

Can someone please let me know if I can do this?

thanks,

Paddy

to post a comment
JavaScript

25 Comments(s)

Copy linkTweet thisAlerts:
@KorMar 02.2005 — try

top.frames['iframename'].window.scroll[color=red]T[/color]o(x,y)
Copy linkTweet thisAlerts:
@KorMar 02.2005 — If you want to go top of the page in iframe, I guess that you could also use a HTML solution


<a href="iframe.html#" target="iframename">go top of the iframe</a>

(this case don't forget to use a transitional DTD)
Copy linkTweet thisAlerts:
@A05087authorMar 02.2005 — Thanks for the reply.

Can I put this JS in the web page that is inside the Iframe?

I'm only responsible for the web which is inside the Iframe and not the page that is outside.

but I need to controll the outside scroll bar
Copy linkTweet thisAlerts:
@KorMar 02.2005 — eeeer, I thought it it otherwise... my code will controll the page in iframe scrollbar.

Anyway, if the iframed page and the main page are from different domanins, there is no way to reach one from within other from obvious security reasons.
Copy linkTweet thisAlerts:
@A05087authorMar 02.2005 — Sorry I forgot to mention that I don't want to move the scroll bar just to the top. I need to move it to the same location after clicking on a link.

Inside the Iframe I have more that 3 pages of drop downs, and when the drop down is open the screen moves to the top, I need it to move to the same location.

Problem example:

A user scrolls to the bottom of the page, 8000px down, clicks on a category and the category opens but the page refresh causes the parent scrollbar to move to the top. the user will have to scroll down again to look at the sub-cats.

If it help this is being developed in Lotus notes.
Copy linkTweet thisAlerts:
@KorMar 02.2005 — 
I'm only responsible for the web which is inside
[/quote]

As I said... If the main page is from other domain (and I presumed that, as you said you can not control the main page) there is NO way to reach it. There is a security implemented issue in all browsers to prevent cross-domains control.
Copy linkTweet thisAlerts:
@A05087authorMar 02.2005 — Ok thanks,

can I call JS on the outside page from the page that is inside the iframe?

I'm just thinking if I ask the other team to place some JS on there page to move the scrollbar I can call it from my page.
Copy linkTweet thisAlerts:
@KorMar 02.2005 — How can I make you understand that it is not a matter of "the other team's" good will. If the two pages are from different domain you CAN NOT modify one from another. This is how the WEB is build from the begining, it is a matter of protocols specific nature...

Well, you could submit some values to the other team's server and the other team should build a server-side application which will bring the main page's scroll to a desired position, this is all you could do, but this is not a javascript solution anymore....
Copy linkTweet thisAlerts:
@Warren86Mar 02.2005 — A05087:

You might try the following. Test.html saves the current scrollbar positions of the main window onbeforeunload, and then onload it restores those positions.

---------- Main document ------------

<HTML>

<Body>

<IFrame Name = 't1Frame'

SRC = 'Test.html'

Height = 200

Scrolling = 'yes'>

</IFrame>

</Body>

</HTML>

------------ Test.html ----------------

<HTML>

<Head>

<!-- <meta http-equiv="refresh" content="10"> -->

<Script Language=JavaScript>

function getPrevScroll(){

if (document.cookie)
{
posStr = document.cookie;
startSlice = posStr.indexOf("=");
endSlice = posStr.length;
lastPos = posStr.substr(startSlice+1,endSlice);
lastPos = lastPos.split(":");
parent.frames.window.scrollTo(lastPos[0],lastPos[1]);
}
}

function saveScroll(){

xSave = parent.frames.document.body.scrollLeft;
ySave = parent.frames.document.body.scrollTop;
document.cookie = "scrollPos"+"="+xSave+":"+ySave;
}

window.onload=getPrevScroll;
window.onbeforeunload=saveScroll;


</Script>

</Head>

<Body>

This is the Test.html document.

</Body>

</HTML>
Copy linkTweet thisAlerts:
@KorMar 02.2005 — Warren...Read all before post ... The parent and the iframed page [b]are not on the same domain[/b] (or at least A05087 says so), thus it woun't work!
Copy linkTweet thisAlerts:
@Warren86Mar 02.2005 — Kor:

This isn't YOUR forum. I don't take orders from you. Shove it.
Copy linkTweet thisAlerts:
@KorMar 02.2005 — It was only a suggestion, you don't need to be offenced, as long I was extremely polite. It is not my Forum, but it is not yours either. So, if you don't read attentively the posts and you insist to give wrong solution, I feel that you are waisting [b]my[/b] time and the [b]others[/b] time as well...
Copy linkTweet thisAlerts:
@Warren86Mar 02.2005 — KOR:

Don't stand in judgment of me. It's not for you to decide what works or not. You are not God, but you are arrogant and self-important. Go run your big mouth at someone else. I am not going to take any more lip from you or anyone else. I will post a comment to any thread I choose. ANY THREAD. If you don't like what I post, too bad. I don't care if it wastes your time or not. I don't give a damn about you. Go play your asinine, juvenile game with someone else, and get your damned finger out of my face. I've had it with your lip, and and your attitude. If you don't like my code, or my comments, kiss my a..

You and others have a chilling effect on other people who want to participate here in good faith. Every time someone posts a comment in a thread, here you come, criticizing them for no other reason than you have a big mouth. After two or three times, the person says to himself, "gee, if I post my solution, KOR is just going to come along in 30 seconds and tell me how wrong I am. I'll just forget it."

I am sick and damned tired of your mouth. You are the one who wastes time by posting your childish, trivial criticism of others for no damned good reason. None. Go run your big mouth at someone else, and get your damned finger out of my face!
Copy linkTweet thisAlerts:
@KorMar 02.2005 — You were wrong, and I said that your solution is wrong. That is all. The rest of your comment has nothing to do with javascript or good behaviour.
Copy linkTweet thisAlerts:
@Warren86Mar 02.2005 — Shove it. The only thing "wrong" is your abusive arrogance. I'm not going to take any more lip from you, or anyone else. Good behavior? You don't know the meaning of it. Otherwise, you wouldn't go around insulting others, all day, every day.
Copy linkTweet thisAlerts:
@KorMar 02.2005 — ? Dear Sir, someday the admins will ban you off as this is not the first time when you insult the other members here... Sure, you will come back with another nickname.. But, I don't sense your behaviour... Wouldn't be better for your health to find another way to discharge your frustration? It would be better for all of us benefit as well ...?
Copy linkTweet thisAlerts:
@Warren86Mar 02.2005 — You have the abusive mouth. Not me. Right from the first day I started participating here. You are confrontational, right from the first day I started participating here, not me. All I do is post code, and I'm not going to take any more lip from you or anyone else who appoints himself to stand in judgment of me. You are the one who engages in personal attacks. Not me. You are the one posting needless, pointless, abusive, trivial criticism of others. Not me. You have the problem. Not me. You and the other one, who if you look down the right hand side of the main page, all you see is his name, you two, 24 hours a day, 7 days a week, 365 days a year, are the ones try to intimidate others, and take control of every thread, by abusive gratuitous criticism. You are the problem. Not me.
Copy linkTweet thisAlerts:
@KorMar 02.2005 — nuts
Copy linkTweet thisAlerts:
@KorMar 02.2005 — I think you are barking at the wrong tree... maybe you are talking about someone else... You are the only one who accused me of such things... I don't know what are you talking about
Copy linkTweet thisAlerts:
@Warren86Mar 02.2005 — Shove it.
Copy linkTweet thisAlerts:
@KorMar 02.2005 — Intelligent way to solve a quarell... :-) Where are the logical arguments on? Your solution [b]still[/b] woun't fit to the needs, so what can you tell us about that? Is there a way that your solution will scroll the parent, if bot parent-iframe are on different domains? No, there is none. [b]This[/b] is what we should talk about, my friend...?
Copy linkTweet thisAlerts:
@Warren86Mar 02.2005 — Find someone else to try and manipulate with your juvenile game. You ran your big mouth at me, and now you just brush it aside, with your typical arrogance and have the gall to call me your friend. I despise you.

Life has a way of canceling "mistakes" like you. One day you'll open your big mouth to the wrong person, and learn that first hand.
Copy linkTweet thisAlerts:
@KorMar 02.2005 — Ok, basta...? You have became borring... Find better a chat to pour your extra adrenaline on... I am fed up with it here... Anyway, don't hope that i will negociate your mistakes further. I have nothing special to quarell with u as a person, my goal is only to help people here, not to spare my time with nonsenses... See ya ?
Copy linkTweet thisAlerts:
@Warren86Mar 02.2005 — Shove it.
Copy linkTweet thisAlerts:
@Khalid_AliMar 02.2005 — calm down guys, I don't think this thread is solving any issues n e more , therefore I am closing it.

Please try not be abusive on these forums because it does not portray a good image of yours for other readers as well as forums.

thanks for you cooperation.
×

Success!

Help @A05087 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...