View Full Version : DHTML Window widget samples do not work

02-11-2012, 03:48 PM
1) Script Title: DHTML Window widget (v1.1)

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex8/dhtmlwindow/

3) Describe problem: samples do not work

One of the samples that's supposed to load images.google.com simply does not work. is their a mistake in the code they supply for downloading?

I unzipped the files and the samples do not work when linking to an external url.

doesn't give me much confidence in trying to even use this code or should I continue looking around for something else?

02-12-2012, 06:39 AM
Google has fairly recently changed the code on their site so that you cannot load their content into an iframe. If that's the only problem, I wouldn't worry about it. When loading external content, just make sure you're not loading a site like Google that blocks their content from being loaded in an iframe or one that 'breaks out of frames' either. These latter type are more common than the blocking type like Google. What happens with 'breaks out of frames' sites is that when you try to put their content in DHTML Window's iframe, their content simply takes over the page, as if you had clicked an ordinary link to their page.

Many sites do this to protect their content from being plagiarized. They have every right to do this and there is no way using just javascript to prevent it. And in most cases to do so using other methods would be a violation of copyright.

Google does have an API for custom searches though that you can use for free (and I think more refined versions that are a subscription only service). It makes the results appear to be on your site.

If that's what you're after, use it. Search for:

Google Custom Search

As I say though, if these are the only problems you're having and you don't require a custom search, just pick other sites.

If you're having other problems, they probably can be worked out if you post a link to your problem page.

If you want more help, please post a link to the page on your site that contains the problematic code so we can check it out.

02-12-2012, 02:50 PM

I'd like to ask you an additional question if I may - I do not pretend to be a javascript or DOM person but I'm learning. I can write php till the cows home though... regardless here's my question.

I have an online store that sells parts for 8 different machines. Each machine has a schematic with each part numbered (and each number is hyperlinked). Right now I open the schematics from links on my store using this javascript code:

onclick="javascript:window.open('http://www.mysite.net/xmax-upper/xmax_upper.html', '_blank', 'top=50, left=50, height=800, width=800, status=no, menubar=no, resizable=yes, scrollbars=yes, toolbar=no, location=no, directories=no');">xmax Upper</a>

the target window opens (most of the time) - of course this depends on how people have their browser set - sometimes IE opens a new tab so I have to put specials instructions on the site to tell people to "let windows decide" and sometimes Firefox gives me problems also. This is a royal pain and I'm probably losing customers.

The code I have in my popped-up windows contains this at the top to identify the parent:

<!--// Hide script from non-javascript browsers.
function loadinparent(url, closeSelf){
self.opener.location = url;
if(closeSelf) self.close();

and the links in my popped up window looks like this to target the parent window when clicked:

<a href="javascript:loadinparent('http://www.mysite.net/index.php?main_page=product_info&cPath=116_164&products_id=1295',false);">Part 15</a>

Which brings to the point of my post - if I used this code how would I go about passing the parent url to the popped up window so that the links in my popped up window would target the parent window?

thanks in advance....

02-12-2012, 05:48 PM
If by:

Which brings to the point of my post - if I used this code . . .

you mean the DHTML Window Widget code, you don't have to. But you can't change the address of the parent of a Widget without losing the Widget as the Widget isn't a separate window. It's either content on the parent page (specified inline or in a separate div on the page) or content imported to the parent page via iframe or AJAX. In all four cases, if the address of the parent page changes, the Widget disappears and is gone.

That said, you can access the parent page in all but the iframe method Widget simply by using ordinary javascript, the widget contents are on the parent page. In the case of the iframe method, the page in the Widget is separate and may access the parent page via parent. So from the page in the iframe you could do:

<a href="somepage.htm" target="_parent">Some Page</a>

But clicking on it will change the parent and the iframe holding the Widget page was on the old parent, so it goes away.

You can also do other things from the iframe, like:

<a href="#" onclick="parent.document.getElementById('info').innerHTML = 'Hello from the iframe'; return false;">Say hello on the parent</a>

Then if there's an element on the parent with the id 'info', the message will appear in it.

You could even fetch complex content to the parent via AJAX, and as long as the iframe holding the Widget page wasn't overwritten, it would remain.

The coding at that point could get complex unless you used a script library like jQuery to simplify things (recommended if you go this route). But the advantage is that (if done right, and of course if the user has javascript enabled) no modern browser would block or misinterpret what you intended the client to see.

02-12-2012, 05:56 PM
John - that is great information and much appreciated. My only remaining question is do you know of any method to get a popup window to "stick" or persist if the parent window is changed. I would like my schematics to be able to stay on screen until the user decides to close the popup even though they may be navigating around the parent window and do thinks. I want the pop-up to continue to be displayed so that they do not have to keep re-opening it.

ps: I see you're in SEPA - me too. My office is in Chadds Ford and I live right across the border in Maryland. I'm a WC native originally.

I did see this which gives me a little hope.


otherwise I'm afraid I may have to use frames or some other tool like this page splitter from dhtmlgoodies.com to display my schematics and site at the same time.

02-12-2012, 06:15 PM
I'm not sure if we're following each other. If you're using a true popup window, it will always be there. If you assign it to a variable you can bring it back to the top by setting that variable to .focus(). Some browsers are beginning to ignore this though.

If you're using the Widget code, you cannot change the parent page without losing the Widget. You can import content to it though. It would still be the same page, just have different info on it. The Widget could be brought to focus (if it loses it, it might not) using the Widget code for that.

02-12-2012, 06:26 PM
I'm not sure if we're following each other. If you're using a true popup window, it will always be there. If you assign it to a variable you can bring it back to the top by setting that variable to .focus(). Some browsers are beginning to ignore this though.

If you're using the Widget code, you cannot change the parent page without losing the Widget. You can import content to it though. It would still be the same page, just have different info on it. The Widget could be brought to focus (if it loses it, it might not) using the Widget code for that.

ok - my dilemma is that by using basic javascript window.open I often get zapped by IE and sometimes FF settings that want new windows opened in tabs - which is why I am looking at DHTML. I have found that the widgets such as the one here and this jquery pluign: http://fstoke.me/jquery/window/index.html allow me to open a schematic in a window without being forced into a new tab, but however as you pointed out the popup disappears as soon as the parent window changes and for me that's a shame since I really don't want to make people continually open the schematic. So - I guess that leaves me with no alternative other than to do the split window thing for my store if I want to be able to keep the schematic up on the screen.

what I think I really need is some sort of slider that I've seen on any sites that slides in and out from the right or left side of the screen to display content. The new version of VB has such a slider that contains content and that would be the perfect type of solution for me. But I have not found one of those yet.

02-13-2012, 10:05 AM
I like the idea of using the jQuery based Window Plugin because that makes more sense if you wanted to use jQuery's AJAX routines to import content to the parent. But it would be a completely different model than a true popup.

You could put your jq win up. Links on it could change content on the page that launched it. It would be still be the same page, so the jq win would remain until dismissed.

This requires you to think differently. Instead of having separate pages that load in the browser for each thing a user might click on in the jq win, it would be just the one page, but portions of other pages could be brought in to substitute for and/or augment certain sections on that page.

That's one of the things AJAX can do, bring all or part of another page into a section of the existing page, actually writing it to the existing page's DOM.

But I'm not certain if the JQuery Plugin is a good fit because this is the first I've heard of it. It looks robust though, so it probably is. And then there would be working out all the gory details. But it could probably be done.

02-13-2012, 02:09 PM
John - thanks so much for your feedback - it is much appreciated.

I just had an idea....

There is one part of the screen on my store that contains a link to all of the schematics.

How about if I create that part of the page as an iframe calls the dhtml that creates the pop up windows. Therefor the popup would be the child of the iframe not of the main page.

Therefore since the iframe is shown on all of my pages on the website would the popup NOT detect that the parent window had changed even through links in the popup would target the parent of the iframe. I have not figured out how to do that part but since the parent to the popup (which is the iframe) is not changing the popup would persist?

just a thought mind you.

The jquery code I have is working but as expected the popup disappears as soon as the parent window changes.

John - Care to collaborate on me with this little project? I could use the help.

02-13-2012, 04:59 PM
An iframe is part of the main page. So even if the next page opened an identical iframe, the one that had produced the popup would be gone. If you had a frame, that could work.

If using the jQuery script, instead of changing the parent page, pick or make a division on it with a unique id - say 'result':

<div id="result"></div>

You can have stuff in there to start out if you like. Now instead of changing the page with:

<a href="somepage.htm" target="_parent">Some Page</a>

You could do:

<a href="somepage.htm" onclick="parent.jQuery('#result').load(this.href); return false;">Some Page</a>

and it should load the contents of somepage.htm into the result division on the parent page. I say should, because I'm not sure if it will look on the parent for result or in the iframe. Try it, we can work it out if need be. It should probably be done as a function on the parent page anyway. This is just a test to get things started. Also, once we have it working, we can pick what part of the external page we want to load into the parent.

I just tested this in a simple local simulation and it works in theory.

02-13-2012, 05:16 PM
frames : now that's a cool idea....

I could create a page with 3 frames and show my existing site in the center frame and have a box in the right hand frame that shows my schematics.

my only concern then is how to get the popup to be draggable over any of the three frames (which would be basically invisible to the user).

02-13-2012, 05:32 PM
That's really hard, perhaps impossible*, and another reason why the jQuery .load() method would be good. You would just have to start thinking in terms of loading content rather than pages to the parent. The good news is that this content can come from pages, so you shouldn't have to change the pages too much.

*a user here called molendijk has done a lot of work with things like that though. Even though I think it's not the way to go, even if it works, if anyone could work it out, he probably could. He's still fairly active, if it's really the direction you want to go in, you could PM him.