Reputation: 33
if (window.parent.frames['scripts1']) {
if (window.parent.frames['scripts1'].document.documentElement) {
var strSCRIPT = window.parent.frames['scripts1'].document.documentElement.textContent;
if ((strSCRIPT.lastIndexOf('bbbbEND') - strSCRIPT.length) != -7) {
window.parent.frames['scripts1'].document.location.href = 'test1.txt?refresh=' + Date();
}
} else {
window.parent.frames['scripts1'].document.location.href = 'test1.txt?refresh=' + Date();
}
}
I have tried lot of things but not success in writing something for cross browser.
Upvotes: 0
Views: 165
Reputation: 1392
Here's some jQuery conceptual material to get you started:
// make sure to give your frame an ID, and then it's easy to access
var frame_a = $( "#frame_a" );
// jQuery's content() function seems to only work on iFrames, not on Frames
var frame_a_document = $( frame_a[0].contentDocument );
var frame_a_document_body = frame_a_document.find( "body" );
var frame_a_text = $( frame_a_document_body ).text();
alert( frame_a_text );
Keep in mind this important fact: Your frame is loaded after the parent document is finalized which means that the ready() function will be executed before the frame is loaded. If you try to access your frame in your ready() function, most likely you will get nothing because it's not been loaded yet -- i.e., it's race condition.
Upvotes: 0
Reputation: 339786
First, refactor your code to eliminate repetition:
var s = window.parent.frames['scripts1'];
if (s) {
var d = s.document;
var e = d.documentElement;
var t = e ? e.textContent : null;
if (!t || t.length - t.lastIndexOf('bbbbEND') != 7) {
d.location.href = 'test1.txt?refresh=' + Date();
}
}
There's one identified compatibility issue but at least now we've got a chance of spotting it!
Specifically, .textContent
isn't supported in IE8 or earlier, hence:
var s = window.parent.frames['scripts1'];
if (s) {
var d = s.document;
var e = d.documentElement;
var t = e ? (e.textContent || e.innerText) : null;
if (!t || t.length - t.lastIndexOf('bbbbEND') != 7) {
d.location.href = 'test1.txt?refresh=' + Date();
}
}
Upvotes: 2