Forum Moderators: open
I want to be able to disable a link depending on the URL of the page in an <iframe>.
I can do this if the URL is in the address bar using 'InString=top.document.URL' but I have tried every whichway to get it to work with my <iframe>.
My code looks like this.
function disLink(FName, LText, MText) {
InString = top.document.URL
LastSlash=InString.lastIndexOf ('\\', InString.length-1)
OutString=InString.substring (LastSlash+1, InString.length)
if (OutString == FName) {
document.write ("<font class='dllink'><b>"+ LText +"</b></font>")
}
else {
document.write ("<a href=" + FName + " target='_top' onclick='blur(); window.status=\"" + MText + "\"; return true' class='dlink' onmouseover='window.status=\"" + MText + "\"; return true'><b>" + LText + "</b></a>")
}
}
So, what do I need to change to get it to work with my <iframe>'s URL and to what do I need to change it to?
Many thanks in advance.
Pantyboy
I think this is why ajkimoto suggested using the src value, but this assumes the iframe was loaded by the parent.
When I use <button> example, the getElementById works and works well. The problem is, it doesn't work in this instance.
The first document is loaded with the page. A button is then clicked and the document in the <iframe> is changed. So that I can change the look of the button depending on which document is loaded into the <iframe>, I need to to be able to get the URL of the <iframe> document and that's the problem.
The documents loaded into the <iframe> are in the same domain just different directories.
Regards
Pantyboy
top.fraOne.document.URL
If you used the same value (fraOne) for an id, the syntax would be:
top.document.getElementById('fraOne').document.URL
You see, there are two document objects in the scope chain of the latter. (By the way, I don't mean to imply you should have an element with both a name and id attribute that have the same value. You can have both attributes, but conflicts can develop if they have the same value.)
I've found where I was going wrong and it's was so obvious, I need a good kicking.
First, Rambo Tribble. The expression 'top...' is the right one for my use. Once I figured out what the problem was, it worked like a dream.
The problem was - and I think you'll agree I should be taken to one side and given a real good slap - I was loading the <iframe> after the script, so as far as the script was concerned the <iframe> didn't exist. When I loaded the <iframe> first and the script second, it worked.
Once again, many thanks
Pantyboy (right royally slapped)