Replace Pop-Ups with dynamic includes using DOMinclude (updated)

Update 25/05/06: DOMinclude now supports only one include window at a time and closing include windows from external files.

Pop-up windows are a pain for both the developer and the users. Often enough a page needs to link to a terms and conditions document and as the client does not want the user to leave the page you are asked to implement them in a pop-up.

The problem with this are technical and psychological:

  • years of unsolicited pop-up windows have conditioned users to immediately close windows when they open
  • the same reason and security concerns made people install pop-up blocker software and browsers to include pop-up blocking options, and depending on their configuration these may even block your “friendly pop-ups”.

One solution is to use JavaScript to create a new layer with the content of the document when JavaScript is available and simply link to the page when it isn’t.

DOMnclude is a script that does that for you

Following is an example what it does to a normal link when you add a certain CSS class. Enjoy, and kiss those pop-ups good-bye.

Update: Would people who have IFRAMES blocked please test the version that checks for blocked iframes? You should be sent to the page instead of trying to load the page into the layer when you click the “Amber Spyglass” link in the demo page. Please comment below if it works then I will include the fix.

DOMinclude example

59 Responses to “Replace Pop-Ups with dynamic includes using DOMinclude (updated)”

  1. aNieto2K | Lo que quiero, cuando quiero y como quiero » DOMinclude, popups dinámicos con Ajax Says:

    [...] OMinclude, popups dinámicos con Ajax
    Abril 11, 2006

    Via Ajaxian, descubro DOMinclude, una curiosa aplicación para crear pop-ups dinámicos. [Download] [Ejemplo][DOM con Ajax] [...]

  2. Dee’s-Planet! » DOMInclude: Replacing pop-ups Says:

    [...] DOMInclude: Replacing pop-ups DG under: Java , Scripts , Library DOMInclude is a library that allows you to add inline dynamic includes of content rather than using wi [...]

  3. otro blog más » Unos cuantos de desarrollo web (XCI) Says:

    [...] title=”Replace Pop-Ups with dynamic includes using DOMinclude (updated) – Wait till I come!” href=”http://www.wait-till-i.com/index.php?p=263″ hreflang=”en”>pop-ups mejorados, pestañas, más pestañas y todo un volumen sobre el tema: From DHTML to [...]

  4. webmasternewsblog.com » Blog Archive » Says:

    [...] what do you think? There’s no question about the coolness of Chris Heilmann’s DOMinclude script (hint: it’s very cool). DOMinclude provides an alternative to pop-ups by gener [...]

  5. Wordpress 2.0 & Typo themes - Desiloper » Replace Pop-Ups with dynamic includes using DOMinclude (updated) Says:

    [...] Replace Pop-Ups with dynamic includes using DOMinclude (updated)

    http://www.wait-till [...]

  6. Sébastien Says:

    Hi, thanks again for a neat script.

    I have a problem with it on Opera though, because I have disabled iframe (I hate iframes, I won’t re-enable them anytime soon).

    I think you should at least have some alternate content to indicate what’s going on to marginal users.

    I would really like an Ajax version where you could also pull the content from a specific file or from a DB, but that could now be inserted in a simple div.

    I know it’s big change, just suggesting.

  7. Chris Says:

    Hmm, might have to check how I could see that the iframe was blocked. I disagree a bit on the AJAX solution – although I will offer one of those. AJAX only works with local files, so you will have to write a PHP script to scrape the document of the third party site and that is not possible all the time either.

    It is dirty, but not as dirty as a popup is. And you hating and turning off IFRAMES is a choice that is not that common.

  8. Sébastien Says:

    I agree that I am a “marginal user”…

    Anyway I thought you could put alternate content for iframes within the opening and closing tags. UAs that render iframes don’t display that content while others display only that content (NB: The blocked iframe test page seems to be down at the moment).

    The other problem with iframe is it invalidates strict markup.

    As for the Ajax “solution” it was just an idea off the top of my head. I have no idea how to actually do it, that’s why I asked (that and also, I’m lazy).

    BTW disabling iframes is a great way to easily disable Google ads and others in one fell swoop, while being able to re-enalbe them at a moment’s notice, unlike a HOST file.

  9. Chris Says:

    Sebastien, have you taken a look at the IFRAMES checking version advertised above? I did this at your request, and would be grateful for feedback from a user that is affected.

  10. BillSaysThis Says:

    Chris, neat stuff!

  11. Sébastien Says:

    Sorry Chris,

    As I said, the page was not accessible at the time.

    I was able to check it just now and it works. On Opera with iframes disabled I simply go to the page when clicking the link.

  12. BillSaysThis Says:

    Chris, is it possible to have the contents of the popup delivered from a JavaScript call? My specific use case is showing the most recent entries from a different blog through the Feed2JS script (which already works for me on the same site called directly, so I’m pretty sure that’s not the problem.

    Thanks!

  13. Dennis Says:

    It looks like the “Terms and Conditions” DOMinclude link causes the nightly build of Safari to core.

  14. Bjorn Says:

    You’re obviously a skilled JavaScript and CSS coder, why must you waste your talent on new ways to deliver unwanted content? Ads are terrible, and hopefully this fad will just end up being blocked as well. I’ll end up writing a Firefox extension that eliminates these new nuisances, if gets to that point. Nobody wants to see ads man. Stop littering the internet.

  15. Chris Says:

    @Bjorn: Where did you get the impression I want people to use this for advertising? It is a nice option to include smaller content bits in the page without going to another page, that is all. This automated response to anything pop-up-ish is worrying, paranoia will get us nowhere.

  16. frank stepanski Says:

    Awesome stuff…Maybe one day I’ll be half as smart as you!

    Thanks

  17. Bill Says:

    Hi Chris, reading your articles, I am totally converted and can’t wait for your new book. Playing around with DOMInclude, I was using it to popup a full size image form a thumbnail link. This works as described in firefox but all W3C DOM versions of IE place the full size image below the thumbnail, not the link. (The link is in the paragraph that describes the, floated to the right, thumbnail image). Can this be fixed? Bill.

  18. Luis de la Orden Morais Says:

    Hi Chris,

    I checked the Iframe blocked version in IE6 with pop ups blocked and security settings to the highest and the only difference in functionality is that instead of displaying in the iframe, one goes straight to the stand-alone pages where the puppy dog pic and terms text are.

    Cheers,

    Luis

  19. E|A Says:

    Not working in IE 6.0.2900…

  20. Chris Heilmann Says:

    e|a it does here (proof screenshot). Are you sure you don’t have some IFRAMES blocking software enabled? If so, try the version linked above.

  21. Tony Hirst Says:

    Chris-
    I’m still finding my way with js, so hopefully you’ll forgive what’s probably a naive question – is there an obivious tweak to the script that will open the popup via a mouseover event on the link, rather than a click on it? I’d quite like to use this widget for a link viewer (e.g. my original proof of concept, which also needs updating to use JSON).
    My coding abilities are largely limited to reusing stuff I find and hacking it around till I can get a proof of concept half working, so any hints appreciated…
    thanks
    tony

  22. Ceon Says:

    Hey, good script, but the loading image doesn’t work with Ie, only with firefox!

    good job, bye.

  23. Budi Irawan Says:

    awesome stuff..thanks for sharing

  24. jeremiah Says:

    I like a lot. But it seems there is a bug if you click on a second pop up link when a first one is open, e.g. if I click on the terms and conditions link and then without hiding it click on the puppy link the results are unexpected.

    I’m wondering if closing the “popup” on a click anywhere outside of the popup would be more intuitive?

    Great stuff at anyrate!

  25. Bob Says:

    One enhancement I’ve had no success in adding is a way to specify different size windows. Could someone drop a hint (if it’s even possible)?

    Thanks!

  26. Bob Says:

    I reread the comment and it could be a little more clear.

    I’d like to have different classes like DOMpop640, DOMpop760, etc or something that would let me have different size windows on the same page.

  27. Jill Says:

    Neat! thanks!

  28. Gobezu Sewu Says:

    Nice one but does not work with IE6

    Edit: Interesting, I must be hallucinating as it does work here

  29. mastorna Says:

    Any idea how I can call a DOMInclude from flash?

  30. John K Says:

    Any suggestions on how to close the popup from within the Iframe?

    When the DOMinclude uses an IFrame, I’d like to have a “CLOSE [X]” link inside the IFrame. However, I can’t find a way to have the event on the “CLOSE [X]” call killPopup with the right event passed.

  31. Scott Says:

    I’m also looking for a way to close the popup from within the iframe. I want to use this to confirm a delete so that when user clicks a confirm link inside the iframe it 1) does the delete, 2) closes the iframe, and 3) reloads the main page.

    The first step is easy but I’m stuck on the others. Any suggestions would be welcome. Thank you.

  32. Scott Says:

    Someone pointed out that an easy solution for what I needed was to include my script in the parent page and then reload it with a link in the iframe, using target=”_parent” in the href.

    It would still be nice to have a way to close the iframe without reloading the page though, for other cases.

    Scott

  33. mitch Says:

    I’d also like to know how to close the popup from within the IFrame.

    thanks.

  34. Chris Heilmann Says:

    Added the closing feature now.

  35. Joe Says:

    I like your dynamic menu script (yadm). How much would it cost to use it unrestricted and unlimited?
    Not to distribute – just use as nav on sites.

  36. Nocs Says:

    I am trying to apply dominclude on Image hyperlink, F.E.:
    tag.
    Works fine with FireFox, but got error in IE.
    The error message is:
    Error: Unknown runtime error
    Code: 0

    Good script Chris

  37. Mark Says:

    Is there a way to include dynamically a term like “+Read” before the user defined text?

    This way it is removed when the pop is open and is replaced with Hide.

    My reasoning is to prevent people from assuming it is a link to a new window or link out of the current page.

    You can get a feel for what I am talking about here.

    Thanks for an excellent script and your help!

    Mark

  38. Elbert Says:

    Very nice. Someone had asked earlier whether this script could be modified for mouseovers rather than onclicks. Would that be difficult?

  39. Chris Heilmann Says:

    Not difficult, just very annoying…

    You’d need to set mouseover and mouseout handlers on the links AND on the “popup”, and you block out keyboard users.

    As a laptop user using trackpointers exclusively I am very annoyed with fiddly mouseover stuff

  40. Mark Says:

    If the user has to actually mouseover to get a response it defeats the whole purpose. I was hoping there was a way similar to the inhtml that is curently used.

    I know very little about scripts but I am learning the lingo. Speak the language but don’t make me read and write it thing ;-)

  41. Lucas Says:

    Hello, thanks for your efforts on this Chris. I plan to make wholesome use of it. (And possibly buy your book as well. ;-)

    However, missing from your How To instructions is the need to also link/insert the three classes from the DOMinclude.css file. Without those, the iframe shunts to the bottom of the page.

    Cheers,

  42. Chris Says:

    Just tried DOMinclude in Firefox 1.5 and spotted a potential problem for keyboard-only users. The puppy image was OK. But with the Terms and Conditions example it was impossible to tab into the text area and scroll down to read anything. Hope this helps you with further development of the script.

  43. Shane Says:

    Hi, thanks for making these excellent scripts.

    I just have one question: I am also using your domcollapse module which is working great. However, when your DOM popup is activated in an expaned section and then collapsed the popup remains.

    My preferred solution would be to close the popup if it is in the collapsed section, but closing the popup regardless of its position would be acceptable.

    I can see I should be calling DOMinclude.killPopup() but I’m not sure where or how I should call it.

    Thanks in advance.

  44. RunningBeare Says:

    Hi, very cool script. I, like Bob would like to be able size the popups on the fly depending on the content. Has anyone worked out how to do this?

  45. Sim Says:

    Any reason why the layer would load in the page’s footer instead of below the link ? Both documents are valid.

  46. Andrew Says:

    How about including a demo of this tool in the page so we don’t have to download it to see it?

  47. Agron Says:

    Does anyone know why windows are opening behind the current table, into the background? Is there any attribute that makes them show up in the foreground?

  48. Mr Echs Says:

    How do I trigger this other than from a link? Is that possible.

    I need to open the popup from within an accordion (mootools) and so can’t just make it a link as this breaks the accordion.

    I have an event linked to the correct opening box then am trying to call the event

    if (toggler.parentNode.id==”mapheader”){
    alert(’stuff’);
    DOMinclude.openPopup(this);

    Clearly ‘this’ is not what’s needed

    Can you help please?

    TIA

    }

  49. Michael Says:

    Closing the iframe from within works with a link like href=”#” onclick=”javascript:parent.DOMinclude.killPopup(); BUT to reopen it, you have to click the DOMpop-Link twice. What am I missing?

  50. charles Says:

    Just wanted to write to express a problem that I am having getting this too work correctly. Actualy I can’t get this to work at all. Would great appreciate your help with this. This could greatly help with space saving on my website. Thanks and hope to hear from you soon.
    The dom llink that I have is the terms and conditions link.

  51. Pop Up Blocker - Downloads for Free - Stop Those Annoying PopUps Says:

    [...] Wait till I come! ? Blog Archive ? Replace Pop-Ups with dynamic …Chris, is it possible to have the contents of the popup delivered from a JavaScript call? My specific use case is showing the most recent entries from a … [...]

  52. This site is gone. For info about killing popups check Google … Says:

    [...] Wait till I come! ? Blog Archive ? Replace Pop-Ups with dynamic …Popup Blocker is a Browser Helper Object (BHO) that eliminates all popup and popunder windows, including those opened automatically by script.; Author: John … [...]

  53. Wait till I come! ? Blog Archive ? Replace Pop-Ups with dynamic … Says:

    [...] Wait till I come! ? Blog Archive ? Replace Pop-Ups with dynamic …Popup Blocker is a Browser Helper Object (BHO) that eliminates all popup and popunder windows, including those opened automatically by script.; Author: John … [...]

  54. #Beginner - Popups Tutorial, What they are, and How to write them Says:

    [...] Wait till I come! ? Blog Archive ? Replace Pop-Ups with dynamic …Popup Blocker is a Browser Helper Object (BHO) that eliminates all popup and popunder windows, including those opened automatically by script.; Author: John … [...]

  55. David Says:

    Hi. I’ve used DOMInclude in my site to load an Iframe containing 3 links which have the result of reloading the main window using 1 of 3 URLs (see code below). Works well for my IE6 users but am getting problems running from Windows Mobile 5.0: Scripting is enabled on the Mobile. The Iframe loads as expected containing a page with 3 hyperlinks. So far so good. But clicking any of the 3 links does not reload the main window.

    Any idea why this worked in IE6 but not Windows Mobile 5.0.?

    In the iframe page : <a href=”#” onclick=”parent.PopUpNavigation.CanComplete(”);return false;”

    JavaScript in the main page:
    PopUpNavigation={
    ifrContainer:null,
    currentTrigger:null,
    CanComplete:function(taskid)
    {
    document.Form1.submitTaskId.value = taskid;
    document.location=’nextpage.aspx?taskid=’+taskid;
    }
    }

  56. zefamedia » Blog Archive » Environmentally Friendlier Pop-ups Says:

    [...] the content of the document. If JavaScript isn’t used it simply links to the page instead. DOMInclude is a library that allows you to add inline dynamic includes of content rather than using window [...]

  57. pascal Says:

    hi
    I discover your site digging the web to find a clean popup solution to show some text or img contents to my pupils when they look at a castle (see the link above)
    it is a big picture mappped: do your code deal with that or not?
    here is the code i use :

    thnks for sharing !
    pascal

  58. pascal Says:

    oops the code disappears…
    hi
    I discover your site digging the web to find a clean popup solution to show some text or img contents to my pupils when they look at a castle (see the link above)
    it is a big picture mappped: do your code deal with that or not?
    here is the code i use :

    thanks for sharing !
    pascalv

  59. Chris Says:

    I guess it could. I am on my blackberry now so I cannot debug this, but I can look at it when I get back home after christmas :)

Leave a Reply

Wait till I come! is the blog of Christian Heilmann , a developer evangelist living and working in London, England. Download vcard.

Feed me, Seymour: Entries (RSS) and Comments (RSS).