PDA

View Full Version : Auto Resize Height Iframe Help!!!



compuwizards
03-23-2007, 07:17 PM
Hello Guys,

I have spent days looking for a IFrame Auto Resize script that actually works!


I came accross the Dynamic Drive SSII Script: http://www.dynamicdrive.com/dynamicindex17/iframessi2.htm


The problem with this script is that it doesnt take you to the top of the page.

See Example: http://www.shopsignaturefashions.com/shop2.html


The script works great resizing the i-frame, but if you are located at the bottom of a page, and you click on a link your page wont refresh to the TOP.


Someone Help! Is there any modifications to the script to fix this problem!

jscheuer1
03-23-2007, 08:28 PM
There is no reason why it should. If you want it to, you can do something about that. I am assuming that most of these links are on the page(s) in the iframe. If so do a:


<a href="whatever.php" onclick="parent.window.scrollTo(0,0);return true;">Link Text</a>

If more than one layer of pages is involved, this might be better:


<a href="whatever.php" onclick="top.window.scrollTo(0,0);return true;">Link Text</a>

If your link is on the top page:


<a href="whatever.php" onclick="window.scrollTo(0,0);return true;">Link Text</a>

compuwizards
03-23-2007, 10:39 PM
Thank you so much for your response!

Is there a way to incorporate the script mentioned on the IFRAME Script.

In another words, there is alot of links, and is PHP Pages, I can go in there and edit all those links manually.



url: http://www.shopsignaturefashions.com/men.html


So if there is a way to modified the code for IFRAME SSII From Dynamic Drive to automatically RESIZE PAGE, and SCROLL TO TOP Standard.

<a href="whatever.php" onclick="parent.window.scrollTo(0,0);return true;">Link Text</a>
If more than one layer of pages is involved, this might be better:

Code:

<a href="whatever.php" onclick="top.window.scrollTo(0,0);return true;">Link Text</a>
If your link is on the top page:

Code:

<a href="whatever.php" onclick="window.scrollTo(0,0);return true;">Link Text</a>




Thank you so much!

jscheuer1
03-24-2007, 03:10 AM
Well, first I'd try a few out manually to make sure it does the trick and to determine which code you want to use. I think that:

top.window.scrollTo(0,0)

will work in most situations. The only problem with that would be if there is another page on top of everything else including the page with the iframe on it.

Once you've determined which code you like, you can make up a script to assign it to all links on a page:


(function(){
function add_to_links(){
function added_click(){
top.window.scrollTo(0,0);
return true;
}
var l=document.getElementsByTagName('a');
for (var i = 0; i < l.length; i++)
if ( typeof window.addEventListener != "undefined" )
l[i].addEventListener( "click", added_click, false );
else if ( typeof window.attachEvent != "undefined" )
l[i].attachEvent( "onclick", added_click );
}
if ( typeof window.addEventListener != "undefined" )
window.addEventListener( "load", add_to_links, false );
else if ( typeof window.attachEvent != "undefined" )
window.attachEvent( "onload", add_to_links );
})();

Save that to a file called add_links.js and put it in the root of your domain. Then on all pages where you want this done put this in the head:


<script src="/add_links.js" type="text/javascript"></script>

That will do it for virtually all modern browsers with javascript enabled.

compuwizards
03-24-2007, 05:17 PM
Thank you!

That works!

enoctis
05-11-2007, 03:11 PM
There is no reason why it should. If you want it to, you can do something about that. I am assuming that most of these links are on the page(s) in the iframe. If so do a:


<a href="whatever.php" onclick="parent.window.scrollTo(0,0);return true;">Link Text</a>

If the pages that are going to be loaded into your iframe are local (on your site), then it would be easier to add the code on each of the pages to be loaded like so:


<body onload="top.window.scrollTo(0,0);return true;">

Just a thought ;) It's what I use on my site @ link removed (mature content)

".enoctis