[thelist] Tricky, tricky problem. capture link location in an iframeof a modal window

James Aylard evolt at pixelwright.com
Fri Dec 19 14:18:39 CST 2003


Scott Blanchard wrote:

> I have a CMS app whose editor has a link inspector to allow users to
> highlight blocks of text and easily create links for them. When they
> click on the "Create Link" icon, a modal dialog (actually its
> modeless) (IE) or dependent (Netscape/Mozilla) window opens that
> allows them to enter a web address in an input field and see a live
> preview of the page they are linking to in an iframe that is located
> in the central portion of this "modeless" window.
>
> Problems I need help with are:
>
> 1) When user clicks on a link or navigates from the initial preview
> page to another page, I need to input field to change to reflect the
> new URL. How would I monitor this to copy the new location value into
> the input field? Is their a location.onchange event???

    Use the onreadystatechange event [1] for the iframe, and check for a
readyState of "complete". Any time the location.href of the iframe is
changed, the onreadystatechange event is fired. This event is IE-proprietary
(IE 5+) afaik.

> 2) If this is done in Mozilla, the links that the user clicks on in
> the preview iframe are opened in the preview iframe, which is what I
> want to happen. However, if the user is in IE, the links all open in
> a new window. I think that this has something to do with the fact
> that I am in a modal/modeless dialog. How can I force IE to open
> those links in the preview iframe???

    Put all of your modeless dialog content within a containing iframe (so
that essentially everything you see within the modeless dialog is actually
contained within an iframe). You can then successfully target a child iframe
within that parent iframe.

1.
http://msdn.microsoft.com/workshop/author/dhtml/reference/events/onreadystatechange.asp

James Aylard



More information about the thelist mailing list