Forum Moderators: open

Message Too Old, No Replies

Scrolling page back to an iframe when a link changes it

         

majestique

10:02 am on Apr 24, 2004 (gmt 0)

10+ Year Member



i have a site that uses iframe.. lets say the iframe's name is main... the iframe is part of a long page..

how do i make a link outside of iframe at near bottom that changes the iframe's link and automatically scrolls the browser up at the same time?

i hope i'm being clear.. basically i want to href="\test.php" & href="#main" at the same time w/ one click.. is that possible?

thanks guys

majestique

6:22 am on Apr 25, 2004 (gmt 0)

10+ Year Member



i even tried <a href="\test.php#main" target="main">Click</a> but it doesn't work eitehr...

majestique

7:58 am on Apr 25, 2004 (gmt 0)

10+ Year Member



I also tried this.. but it doesn't work either :( what does "(this.target)" mean? how do i fill that out?

<a href="http://some.where/some/place/1/" target="iframe"><img src="img1.gif" alt="Click me"/></a>
<a href="http://some.where/some/place/2/" target="iframe"><img src="img2.gif" alt="Click me"/></a>
<a href="http://some.where/some/place/3/" target="iframe"><img src="img3.gif" alt="Click me"/></a>
...
<iframe id="iframe" name="iframe" src="about:blank"></iframe>

If that is the case, you can do what you want with a bit of script magic. Put this in the <head> of the document:

<script type="text/javascript">
<!--
function getSelf() {
var mySelf = null;
if (document.location.href.indexOf("#") > -1)
mySelf = document.location.href.substring(0, document.location.href.indexOf("#"));
else
mySelf = document.location.href;
return mySelf;
}
function goanchor(anc) {
var mySelf = getSelf();
if (mySelf.indexOf("#") > -1)
mySelf += anc;
else
mySelf += ("#" + anc);
document.location.href = mySelf;
return true;
}
//-->
</script>

And then change your links like this:

<a href="http://some.where/some/place/1/" target="iframe" onclick="return goanchor(this.target);"><img src="img1.gif" alt="Click me"/></a>
<a href="http://some.where/some/place/2/" target="iframe" onclick="return goanchor(this.target);"><img src="img2.gif" alt="Click me"/></a>
<a href="http://some.where/some/place/3/" target="iframe" onclick="return goanchor(this.target);"><img src="img3.gif" alt="Click me"/></a>
...
<iframe id="iframe" name="iframe" src="about:blank" class="frame"></iframe>

majestique

8:50 am on Apr 25, 2004 (gmt 0)

10+ Year Member



fixed...

<html>
<head>
<script>
function goToloc(){
parent.location="#anchor"
}
</script>
</head>
<body>
<p><a href="http://www.yoursite.com/" target="frame1" onClick="goToloc()";>Link 1</a>
</p>
<p><a name="anchor"></a></p>
<iframe frameborder="1" name="frame1">bb</iframe>
</body>
</html>

tedster

1:40 am on Apr 26, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sorry we didn't get any help for you - but thanks for keeping us all informed, and I'm glad you resolved the issue. I can see that others will come across the same situation and be very glad for your report.

majestique

2:54 am on Apr 27, 2004 (gmt 0)

10+ Year Member



it's the least i can do =) the whole internet community is so helpful..