Anonymous 0

We have an application that needs a text-based popup to fire when any pages loads. Envision a popup that grays the background and shows a simple white box with some text in it. Below the text is a "close" button that writes a session cookie to keep the box from showing during the rest of the visit.

It is important to mention that I do not have access to the tag. I can only stick html and js in the common footer of the application.

I'm not getting anywhere, fast. I want something minimally invasive that will work in IE6+ and FF. I feel like I'm headed down the wrong path with what I'm designing... has anyone done this?

Thanks

2 answers

1
point

Instead of using document.onload = functionRef; you could attach i with W3C Dom method, maybe this function:

addLoadListener(init);

function init()
{
  // do stuff
}

function addLoadListener(fn)
{
  if (typeof window.addEventListener != 'undefined')
  {
    window.addEventListener('load', fn, false);
  }
  else if (typeof document.addEventListener != 'undefined')
  {
    document.addEventListener('load', fn, false);
  }
  else if (typeof window.attachEvent != 'undefined')
  {
    window.attachEvent('onload', fn);
  }
  else
  {
    var oldfn = window.onload;
    if (typeof window.onload != 'function')
    {
      window.onload = fn;
    }
    else
    {
      window.onload = function()
      {
        oldfn();
        fn();
      };
    }
  }
}

You include it something like this (inside the <body> or <head> tag):

<script type="text/javascript" src="loadEvents.js"></script>

Unobtrusive scripting like this is very powerfull and best (and commin) practice nowadays. Use it always (if not using a library such as jQuery).

Answered about 7 years ago by Jens Hedqvist
  • Good question... what's the best option for a simple text lightbox? Seems like using the photo lightbox might be overkill? Bryan Paepke about 7 years ago
  • Ask it as a new question if you want more replies. "Lightbox" isn't very hard do create. It's just CSS and a little JavaScript. You just need to add some content that represents the modal-box and maybe a class to the body and attach a few click events to the box. The rest is handled with CSS (absolute or fixed positioning). Jens Hedqvist about 7 years ago
  • Thanks Bryan Paepke about 7 years ago
0
points

A library could make this quite simple as most have some form of event normalization for the document loading. For example jQuery has $(document).ready(yourAction)

Answered about 7 years ago by Rob DeSisto
  • True that. If you're doing a lot of scripting on the site a library will save you time and weight. But if you just need a simple script. My example is more lightweight than loading an entire JS-library for one function. Jens Hedqvist about 7 years ago