/    Sign up×
Community /Pin to ProfileBookmark

Regarding MikeFoster’s xWinScrollTo()

Is there a way to use it with the links in another frame than the content to be scrolled?

And do I have to insert the code in every page that needs scrolling or is it possible to just have it one time and decide wich frame it’s targeting (deciding wich frame from the onClick-event)?

thanx for any response! ?
-Mattias

to post a comment
JavaScript

13 Comments(s)

Copy linkTweet thisAlerts:
@HaganeNoKokoroSep 06.2004 — I looked over the xWinScrollTo code and it looks like it would be a little tricky to modify. Here's some code I made that seems to do what you're looking for, although I've only tried it on IE6 and Netscape7.2 (I don't have any other browsers).

Please note: I have borrowed the test text the original coder used to demonstrate his code. The code I have created is a severely simplified and probably less cross-browser-compatible solution I coded to work between frames. It is possible that his code will work between frames as well, although I am too dumb to see a way to do it quickly. I am not trying to take credit for his work in any way.

Original xWinScrollTo Demo: http://cross-browser.com/x/examples/xwinscrollto.php

My files:

scrollFrames.html: This file defines two frames, with id attributes "frm1" and "frm2".

scroller.html: This file defines some links and is displayed within the "frm1" frame of scrollFrames.html. inside the code, it is assumed that the scrollFrames.html frame "frm2" is the target of the links. These links have href='#' and onclick='go(N)' where n is the number of a link in scrollText.html with name attribute lnkN.

scrollText.html: This file contains text and special anchors defined with a name attribute of the form "lnk0", "lnk1", etc. These are the only links that the code in scroller.html cares about.

Edit: Changed links to move directly to the anchor in the "frm2" frame with javascript disabled

[upl-file uuid=650515a3-5ed0-4ded-8132-5078286c37ed size=4kB]scroller.zip[/upl-file]
Copy linkTweet thisAlerts:
@NoumenonauthorSep 06.2004 — okay!

I'll check it out later today after work.
Copy linkTweet thisAlerts:
@MikeFosterSep 06.2004 — [i]Originally posted by Noumenon [/i]

... just have it one time and decide wich frame it's targeting (deciding wich frame from the onClick-event)?
[/QUOTE]


xWinScrollTo should work with frames (the first argument is a reference to a window or frame), and yes you have the right idea of how to use it. Maybe later today I'll get time to put together a demo and test it.

Thanks ?
Copy linkTweet thisAlerts:
@MikeFosterSep 06.2004 — I had to make a few changes, but it works with frames now. It should even work with child windows.
Copy linkTweet thisAlerts:
@NoumenonauthorSep 06.2004 — Great!

I'll go check it out now ?

<EDIT>

Looking at it now. I guess the xlib.js isn't needed for this anymore since it's not inserted in the page.

How do I target a certain frame?

goY('1', 'testFrame')

I've replaced the goTop function with a goX function. Also, this should work with iframes to, right?

</EDIT>
Copy linkTweet thisAlerts:
@MikeFosterSep 06.2004 — Looking at it now. I guess the xlib.js isn't needed for this anymore since it's not inserted in the page.[/quote]
It uses 'x_core.js' and 'x_win.js'.

How do I target a certain frame?[/quote]
xWinScrollTo(windowReference, xCoord, yCoord, msTime)

Also, this should work with iframes to, right?[/quote]
Probably, but I haven't tested it with iframes.

Thanks ?
Copy linkTweet thisAlerts:
@NoumenonauthorSep 06.2004 — cool ?
Copy linkTweet thisAlerts:
@NoumenonauthorSep 06.2004 — Still a bit confused though.

This is inserted in the head of the doc with the links.
[CODE]
<SCRIPT TYPE="text/javascript" SRC="x_core.js"></SCRIPT>
<SCRIPT TYPE="text/javascript" SRC="x_win.js"></SCRIPT>
<SCRIPT TYPE="text/javascript">
function go(n)
{
var t = (n < 5) ? n * 500 : n * 300;
xWinScrollTo(window, 0, xPageY('lnk' + n), t);
return false;
}
</SCRIPT>
[/CODE]


But how do I write a function that gives the 'window' to xWinScrollTo? Like function goY(n, targetFrame).

And for the iframe don't I need something that finds out it's ID?
Copy linkTweet thisAlerts:
@MikeFosterSep 07.2004 — Is your page online? Otherwise I'm just guessing at what you're doing.
Copy linkTweet thisAlerts:
@NoumenonauthorSep 07.2004 — Yeah.

http://212.112.183.83/contents/news.php

That's the page I'm trying your scroller out on. The others still use the old one.
Copy linkTweet thisAlerts:
@MikeFosterSep 07.2004 — Since the iframe has a value for its 'name' attribute you can get the corresponding window object with the expression: "window.frames['news_']"

But you're still using the code from my demo which used the variable 'n' and had named anchors with IDs 'lnk1', 'lnk2', etc. Your iframe source doesn't have IDs like that. Your iframe contains other iframes. So you need to find their absolute Y positions to pass to xWinScrollTo(). xPageY() 'might' work if you try something like...

var w = window.frames['news_'];

var y = xPageY(w.document.getElementById('latest'));

xPageY() 'will' work if x_core.js gets included by the frame source, so you could do something like...

var w = window.frames['news_'];

var y = w.xPageY('latest');

// The main page will have to know the IDs of the iframes contained in the 'news_' iframe: 'latest', 'updates' and 'diary'.

You have iframes embedded in iframes. Each of these is represented by a different "window object" and each window object has its own "document object". You have to carefully consider the contexts of your scripts.
Copy linkTweet thisAlerts:
@NoumenonauthorSep 07.2004 — what I did in the other code was to assign the exact y-pixel to scroll to. could that be a way to do it?
Copy linkTweet thisAlerts:
@MikeFosterSep 08.2004 — Yes, I think that will work ok. ?
×

Success!

Help @Noumenon 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.8,
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,
)...