scrolling framed pages

liunx

Guest
If i want to load someone elses page in my frame, but i want to scroll that page to the info i want to show, how would i do that?<br />
<br />
for instance if the content (of the other site) (that i want to show) is down at the bottom of their page, can i have JS scroll down to where i want the page to show?<br />
<br />
thanks doug<!--content-->You can't do that with any client-side scripting unfortunately. I do believe that PHP can do it (or something like it) although I could'nt tell you how.<!--content-->In IE you can use the scrollIntoView() method.<br />
Create a textRange of the document body, and then invoke the findText() method to look for a string.<br />
<br />
var myRange = document.body.createTextRange();<br />
if (myRange.findText("Motorcycle Maintenance")) <br />
myRange.scrollIntoView();<br />
<br />
Or, in your framed case:<br />
<br />
var myRange = parent.frames.otherFrameName.document.body.createTextRange();<br />
if (myRange.findText("Motorcycle Maintenance")) <br />
myRange.scrollIntoView();<br />
<br />
<br />
This won't work for Netscape Navigator, Opera, NeoPlanet or other minority browsers.<!--content-->Don't bother. It can't be done, as far as I know, except for the previously stated way, which is not a good way to do something.<!--content-->except for the previously stated way, which is not a good way to do something.<br />
<br />
Ahem... And just why isn't it a good way?<br />
Please elaborate.<!--content-->Originally posted by jonhanlon <br />
<br />
Ahem... And just why isn't it a good way?<br />
Please elaborate. <br />
<br />
As previously stated, it doesn't work on Netscape, Opera, etc. You want a page to work for all audiences.<!--content-->i put the following, in the head of my frameset:<br />
<br />
<br />
var myRange = parent.frames.leftFrame.document.body.createTextRange();<br />
if (myRange.findText("10 Day Forecast")) <br />
myRange.scrollIntoView();<br />
<br />
i changed where you had <otherframename> to <leftFrame> (appropriate to my frameset) and change the find text to appropriate text, but no worky.<br />
<br />
here is my page: <!-- m --><a class="postlink" href="http://members.home.net/cassidy147/weatherframe2.htm">http://members.home.net/cassidy147/weatherframe2.htm</a><!-- m --><br />
<br />
Thanks for your time, doug<!--content-->FrameIT should do it for you, but it uses CGI:(<br />
Hope this helps<!--content-->its probly beside the point (cuz of the cgi thing- although i may have access to cgi capability -dunno) - but what is this frameIT?<br />
<br />
anyway this scrollintoview thingy isnt working for me. <br />
<br />
does it go in the head? do i need some onload command or function call or something?<br />
<br />
doug<!--content-->The last time I looked, Gartner reported that Internet Explorer 4+ had 86% of the browser market. It is no doubt higher now. Now I'll admit that a 100% solution is best, but if you can cover 5 out of 6 browsers then you're doing OK in my book.<br />
Anyway, back to the problem. Let's say the target frame concerns itself with Harley-Davidson motorcycles... What you have to do is examine the target document and pick out distinctive pieces of text that will be your 'anchors'. For Netscape, you need to estimate the offset distance from the top of the document to each 'anchor'. Now different screen sizes will result in different offsets (as will different fonts, frame widths, etc.) so do it in, say 800x600 and we'll scale the result.<br />
This is why the IE solution is better. The scrollIntoView method will always scroll the text into the visible screen, regardless of browser settings. For Netscape we have to guess and hope that their browsers are pretty much standard.<br />
Either way though, you'll have to check the target page regularly and re-code any changes.<br />
<br />
<br />
<br />
<a href=http://www.htmlforums.com/archive/index.php/"#" onclick="scrollAbout('FatBoy');return false">Fat Boy</a><br />
<a href=http://www.htmlforums.com/archive/index.php/"#" onclick="scrollAbout('SoftTail');return false">Soft Tail</a><br />
<a href=http://www.htmlforums.com/archive/index.php/"#" onclick="scrollAbout('Sportster');return false">Sportster</a><br />
<br />
<script language="JavaScript"><br />
function scrollAbout(inText) {<br />
var lookFor; // IE string we'll go to<br />
var textSpot; // NN offset we'll jump to<br />
var targetFrame = parent.frames.leftFrame;<br />
switch (inText) {<br />
case 'FatBoy' : lookFor = "The Fat Boy range";<br />
textSpot = 200; // on 800 x 600<br />
break;<br />
case 'SoftTail' : lookFor = "Soft Tail cycles are for";<br />
textSpot = 100;<br />
break;<br />
case 'Sportster' : lookFor = "Built for speed,";<br />
textSpot = 460;<br />
break;<br />
default : return;<br />
}<br />
if (document.all) { // IE<br />
var myRange = targetFrame.document.body.createTextRange();<br />
if (myRange.findText(lookFor)) <br />
myRange.scrollIntoView();<br />
} else { // NN estimate <br />
var factor = Math.floor(800 / screen.availWidth)<br />
targetFrame.scrollTo(factor*textSpot,0)<br />
}<br />
}<br />
</script><!--content-->
 
Back
Top