Saturday, August 21, 2010

How to break frames?

I am designing a page freehand and the customer decided they wanted a gallery with a frame of thumbnails in the left frame and an enlarged in the right.





However, when I click the homepage hyperlink to go away from the gallery the thumbnais frame stays on the left hand side, I don't usually do these frames so I am not good at breaking frames.





Please write the code out in your response so I can stick it in the site, the first one with a code THAT WORKS! wins the 10 points.





please keep it html if you can, if not, JS or PHP.





thanks,


earldbjrHow to break frames?
This is a JavaScript to break out of frames.


Put it in the %26lt;head%26gt; of the HTML document and call it with the onload attribute in the %26lt;body%26gt; tag:





%26lt;script type=';text/javascript';%26gt;


%26lt;!--


function breakingOutOfFrames() {


if (top.location != location)


top.location.href = document.location.href;


} //--%26gt;


%26lt;/script%26gt;





And in the body:





%26lt;body onload=';breakingOutOfFrames()';%26gt;


Web page content goes here...


%26lt;/body%26gt;





If you need the script on several pages it's better to put the script in an external file.


You can read more on how to do that here:


http://www.webpelican.com/blog/2006/05/19/how-to-break-out-of-frames-with-javascript/





I would, however, not use standard HTML frames at all. A better alternative is CSS Frames. You can read more on CSS frames compared to HTML Frames here:





http://www.webpelican.com/blog/2006/03/07/css-frames-vs-standard-html-frames/





Here is an example of CSS Frames:


http://www.webpelican.com/blog/examples/css-frames-example.htmHow to break frames?
%26lt;a href=';[URL OF HOMEPAGE]'; target=';_blank';%26gt;[LINK NAME THAT SHOWS]%26lt;/a%26gt;





This will open a new page for you
The secret is in the use of the target attribute of the anchor %26lt;a%26gt; tag. You can use some of the globally defined targets such as ';_top';, ';_self';, ';_parent';, or ';_blank'; depending on what effect you're looking for.





%26lt;a href=';example.com'; target=';_parent';%26gt;





Alternately, if you have a main ';frame'; and you have given it a name, you can name that as the target, and the new page will take up the entire frame.

No comments:

Post a Comment