Forum Moderators: open
I would like to put a frame into its framed context if it is called up without its frame (e.g. from a search engine result). The following is a cut-down extract of the code I am using. It works great in IE and Netscape, but causes Opera to crash.
In reframing.js:
function CheckInFrame(whichFrame, HomepageURL) {
if (top.location == self.location) {
subframe = document.location.href;
alert('Debug: about to set homepage to ' + HomepageURL + '?' + whichFrame + '=' + subframe);
self.location.replace(HomepageURL + '?' + whichFrame + '=' + subframe);
}
alert('Debug: finished checking we are in frame context');
}function PopulateFrames() {
alert ('Debug: arrived');
originalURL = document.location.href;
contentTarget = originalURL.substring(originalURL.indexOf('?')+1, originalURL.indexOf('='));
contentURL = originalURL.substring(originalURL.indexOf('=')+1, originalURL.length);
if (window.top.frames[contentTarget]) {
window.top.frames[contentTarget].location.replace(contentURL);
}
}
In the main framed index file:
<script language="Javascript">
<!--
onload = function(){PopulateFrames()};
-->
</script>
In one of the frame files:
<script language="Javascript">
<!--
onload = function(){CheckInFrame('left_nav', '../index.html')};
-->
</script>
In NN & IE it works great. In Opera, when I open the index file, it is fine. However, when I open a sub-frame page, it executes the first debug statement (alert('Debug: about to set homepage...), but never gets to the alert('Debug: finished checking... ) (which may not be surprising), and never gets to the alert('Debug: arrived').
I have tried href = contentURL instead of replace(contentURL) but that did not help. I also tried document.URL instead of document.location.href, but that didn't help Opera, and didn't work well in IE.
thanks in advance
Shawn
PS. Pls, no advise to deframe/flatten the site. That is a very debatable topic, but probably shouldn't be debated in this thread ;-) I'd really prefer help with why the javascript isn't working rather than the pros/cons of frames.
I don't like the idea of not supporting Opera; it is pretty popular.
I have selected the option to report Javascript errors, but I don't get any. It looks like an infinite loop with the browser window being constantly refreshed, rather than a Javascript error.
Any other ideas? Is there a Javascript debugger for Opera, where I could put a watch on variables or define breakpoints?
Shawn
subframe = subframe.replace(new RegExp('/', 'g'), '/');
in the CheckInFrame function, and then do the inverse in the PopulateFrames function.
Just for good measure, I also did
subframe = escape(subframe);
Anyone seen this before and/or have a more elegant solution?
Shawn