Darren
09-04-2007, 08:20 PM
Is there an elegant way to determine if my javascript is running at the window level or within a frame? here's two files to demonstrate what I'm talking about:
page1.htm<html><body>
<button onClick="loadPage()">Click me</button>
</body></html>
page2.htm<html><body>
<iframe src="page1.htm" />
</body></html>My function loadPage() is using window.document.open() and writing out a new page. But when it is ran inside a frame (such as it does in the second example above), it writes out the new page into the frame. I want it to overwrite the window at the root level. Both examples use the same function. I was using window.parent, based on the behavior I've observed that if I'm already at the root window, window.parent seems to return itself, but that seems like a quirk and I'm not sure I can rely on that.
Thanks in advance,
Darren
edited:
I just discovered that my problem appears to be tied to the doctype that I send in the document.write() command. When I remove the doctype, the frame button will reload at the root window. But when I have my doctype specified (<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'>) it stops working when I hit the button from within a frame.
Hmmm... any ideas?
page1.htm<html><body>
<button onClick="loadPage()">Click me</button>
</body></html>
page2.htm<html><body>
<iframe src="page1.htm" />
</body></html>My function loadPage() is using window.document.open() and writing out a new page. But when it is ran inside a frame (such as it does in the second example above), it writes out the new page into the frame. I want it to overwrite the window at the root level. Both examples use the same function. I was using window.parent, based on the behavior I've observed that if I'm already at the root window, window.parent seems to return itself, but that seems like a quirk and I'm not sure I can rely on that.
Thanks in advance,
Darren
edited:
I just discovered that my problem appears to be tied to the doctype that I send in the document.write() command. When I remove the doctype, the frame button will reload at the root window. But when I have my doctype specified (<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'>) it stops working when I hit the button from within a frame.
Hmmm... any ideas?