I’m having trouble with a bit of code that works with ie but does not seem to work with firefox. When lookin though the javascript console I discovered that firefox claimed that the document.frames part of the code was undefined. Here is some of the code relevant to the document.frames
document.write("<iframe name='index' src='" + location.href.split("?")[0] + "' style='display:none' onload='harvest()'></iframe>")
function harvest()
{
var div = document.frames["index"].document.getElementsByTagName("div")
for(var i = 0; i < div.length; i++)
if(div[i].className == "thin")
break
var a = div[i].getElementsByTagName("A")
var names = new Array(a.length)
for(i = 0; i < a.length; i++)
names[i] = a[i].innerHTML.replace(/<[^>]+>/g, "")
updateStatus(names)
}
why doesn’t this work in firefox? Why is it undefined?
The use of frames to address an array of iframe objects is IE-only. You can give your single iframe an id, then use getElementById(), or you can create your own array of iframe elements with getElementsByTagName().
I really don’t know what I’m doing any more. My brain isn’t working well and I have been playing with the code and I have realized that I don’t know what I’m doing, this is what I have:
document.write("<iframe id='index' name='index' src='" + location.href.split("?")[0] + "' style='display:none' onload='harvest()'></iframe>")
function harvest()
{
var div = document.getElementById("index").document.getElementsByTagName("div")
for(var i = 0; i < div.length; i++)
if(div[i].className == "thin")
break
var a = div[i].getElementsByTagName("A")
var names = new Array(a.length)
for(i = 0; i < a.length; i++)
names[i] = a[i].innerHTML.replace(/<[^>]+>/g, "")
updateStatus(names)
}
I don’t think I can apply what I have here. I knew it wouldn’t work before I tried it. I don’t know how to do what you have suggested.
At first glance it looks like it might work if you fixed your syntactic errors: You’re missing your curly braces for your for loops; The break command should be on the same line as your if conditional, if that what you’re trying to trigger, or you could use curly braces there; It is really best practice to finish your statements with a semicolon.
… I still can’t figure it out, and I’m doing things I shouldn’t probably.
document.write("<iframe id='index' name='index' src='" + location.href.split("?")[0] + "' style='display:none' onload='harvest()'></iframe>");
function harvest()
{
var div = document.getElementById("index").getElementsByTagName("div");
{for(var i = 0; i < div.length; i++)
if(div[i].className == "thin")break
var a = div[i].getElementsByTagName("A");
var names = new Array(a.length);}
{for(i = 0; i < a.length; i++)
names[i] = a[i].innerHTML.replace(/<[^>]+>/g, "");}
updateStatus(names);
}