2

I have a page that uses an iframe. Underneath that there is a frameset which has two frames. One of the frame id is myframeid. Here is the code snippet.

<html>
<head></head>
<body>
<iframe name="someiframe" src="/app/html/files">
<html>
<head></head>
<body>
 <script>
function thismyfunction(dObj, dTo, dCode){
if (dTo == 'start'){
    if (tempora) {                  
        if (confirm('Is this correct?')){
            window.myframeid.location.href = '/code/cgi/bin';
        }
    } else {                                
        if (confirm('Prefer to view your account?')){
            window.myframeid.location.href = '/code/welcome/account';
}   }   
}
}
</script>
<frameset cols="30%, 70%" FRAMEBORDER=NO FRAMESPACING=0 BORDER=0>
<frame name="someframe" id="topframe" src="/app/source/default.htm" scrolling="no">
<frame name="someframe2" id="myframeid" src="/app/html/load">
  <input type="button" onclick="parent.thismyfunction(this.form, 'start')" 
     id="nicebutton"  value="Hello world" />
   </frameset>
  </body>
 </head>
</html>
</iframe>
</body>
</head>
</html>

This is working on IE 11 but not working on google chrome version 36. Working as in when I click on the button using IE 11 browser, the function works. but not in google chrome. I think the google chrome doesn't like the below code.

 window.myframeid.location.href = '/code/cgi/bin';

Any ideas why? Thank you!

Blair
  • 21
  • 3
  • Have you checked, which object `window.myframeid` is in Chrome? Notice, that the `id` of the said frame is `"right"` rather than `"myframeid"`. – Teemu Aug 27 '14 at 15:16
  • Good find @Teemu ! Thank you!! I edited the page. It was my mistake when posting the question. – Blair Aug 27 '14 at 15:22
  • I doubt that will fix your problem, it was just a conflict between the text and code in the question. `window.name` should refer to `window` object within a frame. Does it in Chrome? – Teemu Aug 27 '14 at 15:25
  • Please put `console.log(window.myframeid)` before trying to set `href` of its `location` object. Then open the console and refresh the page and click the button, what you see? – Teemu Aug 27 '14 at 15:53
  • @Teemu It looks like the function can't reach myframeid. Isn't it? – Blair Aug 27 '14 at 16:05
  • Yep. Please check [this answer](http://stackoverflow.com/a/24096958/1169519). It's not a direct answer to your question, but it contains a lot of useful information and links how to refer `(i)frames`. – Teemu Aug 27 '14 at 16:09
  • @Teemu I looked at that answer. Very informative. Thanks! But I still have no luck. Its funny how it works in IE but not in Chrome. – Blair Aug 27 '14 at 19:47

1 Answers1

0

myframeid is an id, you can get a reference with document.getElementById('myframeid'). You can load a new page by setting its src attribute.

vpzomtrrfrt
  • 483
  • 6
  • 16
  • @vpzomtrrfrt I know where you are going with this. I tried this too but it did not help. – Blair Aug 27 '14 at 15:47
  • @Teemu this what I tried, so far. I replaced, window.myframeid.location.href = 'http://www.yahoo.com'; by the following line; document.getElementById("myframeid").location = 'http://www.yahoo.com'; – Blair Aug 27 '14 at 15:48
  • It did not help. I got this error, Uncaught TypeError: Cannot set property 'location' of null – Blair Aug 27 '14 at 15:51
  • Use src instead of location.href. – vpzomtrrfrt Aug 27 '14 at 20:39