tags:

views:

801

answers:

1

Say I have 3 frames in a frameset arranged in 3 rows. Frames 1 and 3 are from my site and frame 2 (the central one) is from an external website. Is there a cunning way to force the browser to centre align the data in frame 2?

I've found a small work-around which uses a frameset within a frameset which has 2 blank columns either side of the data but that means the scrollbars from frames 2 and 3 are out of alignment.

Any ideas?

Edit : The code I have currently is :

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server" />
<frameset rows="10%,65%,25%" border=0 frameborder="no">
    <frame name="nav" noresize scrolling="no" src='NavigationBar.aspx?NAVIGATION=<%=sDisplayNavigation %>'>
    <frameset cols="1*,1010px,1*">
        <frame name="lspace" scrolling="no" src="border.htm">
        <frame name= "main" scrolling="auto" src='<%=sMainTextURL%>#highlight'>
        <frame name="rspace" scrolling="no" src="border.htm">
    </frameset>
    <frame name="suggest" scrolling="yes" noresize src='<%=sSuggestURL%>'>
</frameset>
</html>
+2  A: 

I think what you are looking for is a way to inject some CSS into the other frame, even though it comes from another site.

I think this will not be possible without a server side script to request the page and modify it.

Javascript has ways to modify other frames using window.frames[] and using DOM traversal just like for elements in the local frame. This will be problematic for you because of the "same-origin policy". This basically means that javascript in a frame loaded from example.com can not access the DOM in a frame loaded from foo.com. Even if you have similar domains, foo.example.com and bar.example.com, they are treated as separate domains in the browser so your javascript from one is not allowed to access the other.

This affects ajax calls using XMLHttpRequest as well. There are ways of reducing the impact of this, but I think you need to be able to run javascript on both sides of the line.

I recently tried something similar to what you are doing, where I wanted to embed one site in another, but the same-origin policy made it impractical.

The other way to do this is server-side instead of client-side. Create a php script which requests content from the other server on behalf of the client, and then serves it as if it was on your server all along. Then your javascript, now on the same server, can do what it will with that frame. If the other site uses a lot of cookies or ajax, this could be tricky, but your php won't have a same-origin policy to deal with.

Mnebuerquo