views:

124

answers:

2

Okay, I have this code:

 <script language="javascript" type="text/javascript">
<!--

function requestPage(page) {

    var request = false;

    try {
        request = new XMLHttpRequest();
    } catch (e) {
        try{
            request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try{
                request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {
            alert("Unable to complete your request.");
            return false;
            }
        }
    }

    request.onreadystatechange = function() {
        if(request.readyState == 4) {
            if(request.status == 200) {    
                document.getElementById('content').innerHTML = request.responseText;
            }
        }
    }

    request.open("GET", "include.php?page=" + page, true);
    request.send(null);
}

//-->
</script>

then obviously making it happen like so:

<a onclick="javascript:requestPage('red_the_clown')"><li>Red</li></a>
<div id="content"><?php include('index2.php'); ?></div>

I have been pulling my hair out trying to work out how to target a separate frame instead of the current frame. I.e.: the #content div will be in _main, but it is being called from a frame.

Anyone have any ideas?

Thanks in advance!

Ryan

A: 

so you have an iframe with id "_main"?

how about

window.frames["_main"].document.getElementById("content").innerHTML = request.responseText;
puffpio
no sorry by main i meant parent (or top, im not sure of the difference)
let me clarify, the link thats requesting is in a frame, the content div that needs to be filled is notwindow.frames["_parent"].document.getElementById("content").innerHTML = request.responseText; doesnt work
+1  A: 

You want to access the document from inside a frame?

top refers to the top most frame. parent refers to one level up.

Your Javascript above might just need one change:

top.document.getElementById('content').innerHTML = request.responseText;

However, you'll need both frames to be from the same domain, or else you'll be restricted by browser security.

seanmonstar
well if he does have x-domain issues he's completely SOL anyway
annakata
ohh top! thats great, thanks alot it worked perfectly.