Mark Canada

Navigation

Skip navigation.

Search

Site navigation

Email conversation

FromMark Canada
ToMe
SubjectDynamically "create" windows using the Movable Windows script
Date10 October 2005 16:06
I am using your Movable Windows script and think it's great. It was so easy
to implement into the application I am writing.

My question is whether or not the script could be modified to dynamically
"create" windows. The windows (call to createMiniWinLayer) has to be done
ahead of time as the page is loading. Once the page is loaded you can
hide/show the windows as needed.

I would like to be able to call the routine when I need a new window to
popup (be created). In other words, I may have a page that would need 10
popup windows but rather than creating them ahead of time, I would like to
create them dynamically as they are needed. I'm not sure if this is even
possible in Javascript. I looked at using innerHTML but I'm not sure if this
would work properly or not.

Any help/tips would be greatly appreciated.

Thanks,
Mark Canada
FromMe
ToMark Canada
SubjectRe: Dynamically "create" windows using the Movable Windows script
Date10 October 2005 16:22
Mark,

> I looked at using
> innerHTML but I'm not sure if this would work properly or not.

yeah, should be possible. After this line:

window.MWJ_MINIWINS = window.MWJ_MINIWINS ? ( window.MWJ_MINIWINS + 1 ) : 1;

add this:

var stringWindow = '';

Then replace:
document.write(
with:
stringWindow += (

Then before this line:

var tempOb = new Object(); tempOb.maxName = 'MWJm....

add this:

document.body.innerHTML += stringWindow;

I _think_ that should do what you need. Let me know if anything fails. (Note
that Opera 7.2- may lose other styles on the page when you do this. That bug
was fixed in Opera 7.5.)


Mark 'Tarquin' Wilton-Jones - author of http://www.howtocreate.co.uk/
FromMark Canada
ToMe
SubjectRe: Dynamically "create" windows using the Movable Windows script
Date10 October 2005 16:25
Thanks so much for the quick reply. I will let you know how it works
out.

Best regards,
Mark Canada
FromMark Canada
ToMe
SubjectRe: Dynamically "create" windows using the Movable Windows script
Date10 October 2005 17:04
This doesn't appear to be working. I probably should have stated this in
my first email. I'm using the movablewindow.js that has been modified to
use iframes by someone else (I got the mods from one of your emails
posted on your site).

I'm not sure if you can dynamically create iframes using innerHTML. This
may not be possible. I need iframes because I am dynamically changing
the location of the iframes to point to different urls.

Can you comment on whether or not this is possible?

Thanks,
Mark Canada
FromMe
ToMark Canada
SubjectRe: Dynamically "create" windows using the Movable Windows script
Date10 October 2005 17:11
Mark,

> Can you comment on whether or not this is possible?

it should be. can I see the page online somewhere so I can see the
problem myself? I will try debugging it.
FromMark Canada
ToMe
SubjectRe: Dynamically "create" windows using the Movable Windows script
Date10 October 2005 18:07
OK, I have it working now. Thanks so much.

I revisited my code and realized what I was doing wrong. The window was
being created in a hidden iframe rather than my main browser window. I
just needed to execute the parent code. Once I did that it worked fine.

Thanks again for the help and the great script!

Mark Canada
FromMark Canada
ToMe
SubjectRe: Dynamically "create" windows using the Movable Windows script
Date11 October 2005 14:42
I have one more question for you; maybe you can help me...

I have a hidden iframe which runs a script that calls the
createMiniWinLayer routine to create a window. There could be multiple
windows that get created.

The problem I am having is as soon as the code in the hidden iframe
executes the createMiniWinLayer routine, the window gets created and
that's it. Nothing else happens. I put an alert after the call and I
don't get the alert.

After this occurs, if I look at the source in the hidden iframe window,
only <html></html> is in the window. It's as though when it does the
innerHTML command the code is cleared.

main frame
   |
   |
   hidden iframe
    execute parent.createMiniWinLayer(....)

I have a main frame which contains a hidden iframe. When windows get
created, they are children of the main frame. From the hidden iframe I
execute the code from the parent so that the window is created in the
proper place.

Any ideas why this might be occurring?

Thanks,
Mark Canada
FromMe
ToMark Canada
SubjectRe: Dynamically "create" windows using the Movable Windows script
Date11 October 2005 22:33
Mark,

> The problem I am having is as soon as the code in the hidden iframe
> executes the createMiniWinLayer routine, the window gets created and
> that's it. Nothing else happens. I put an alert after the call and I
> don't get the alert.
> Any ideas why this might be occurring?

Indeed I do. And sadly this is annoying and largely unavoidable if using
innerHTML. I had a feeling something like this might happen. Basically, the
simple snippet I gave you recreates the pages HTML every time, meaning the
hidden iframe gets recreated and re-initialised.

Ok, we need to use the DOM more effectively them :) The new windows need to
be added to a temporary element (so the required DOM nodes are created),
then they need to be moved into the document. If they are appended to it,
then it should not affect the rest of the document. The temporary element
must be created in the same document as the mini windows are going to end up
in.

this line:
document.body.innerHTML += stringWindow;
gets replaced with this ('document' must be the document object of the
destination window):

var foo = document.createElement('div');
foo.innerHTML = stringWindow;
document.body.appendChild(foo.firstChild);
document.body.appendChild(foo.firstChild);

that should do it, I think.
FromMark Canada
ToMe
SubjectRe: Dynamically "create" windows using the Movable Windows script
Date12 October 2005 15:03
That worked like a champ! Thanks so much.
This site was created by Mark "Tarquin" Wilton-Jones.
Don't click this link unless you want to be banned from our site.