简体   繁体   中英

Javascript: location.href opens a new window

My application is trying to attach a URL to hidden frame by using following syntax.

top.frames['main_frame_name'].frames['sub_frame_name'].location.href = URL

But when my application executes the above syntax, it opens the URL in a new window instead of attaching it to the hidden frame.

My application and frame application are on different domain.

I think you are not referencing your frame correctly, assign an id to frame and set its url by:

document.getElementById('myframe').src = URL;

This should work;

<frameset rows="50%,*" onload="LoadPage();">    
   <frame id="content2"></frame>
   .....

Complete code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
<html>
<head>
<script type="text/javascript">
function LoadPage(){
    document.getElementById('content1').src = "http://www.google.com";
    document.getElementById('content2').src = "http://www.bing.com";
}
</script>
<title></title>
</head>
<frameset rows="50%,*" onload="LoadPage();">    
    <frame src="#" id="content1">    
    <frame src="#" id="content2">                
</frameset>
</html>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM