The Digital Research Initiative The University of North Carolina at Chapel Hill ![]() Other Goodies There are tons of other, littler things you can do with JavaScript to make viewing your page much more of an experience. While you should never overload your page with JavaScript (the occurance of phantom errors increases proportionally with the amount of lines of code), it is nice to have one little trick here and there. These are just a few things you can add. Alert boxes These can be somewhat annoying, but in some cases they can be really great. It all depends on the situation. In an older version of EvenOS, I had an alert box pop up if your browser was JavaScript enabled. It was good at first, but got old real quick. Use discrection when implementing alert boxes. Add this garfle of code in the <head>:
Then you can have an alert box pop up when someone clicks a link with this snip of code,
or you can have it pop up when someone loads the page (I don't necessarily recommend this) by putting this in the <body>.
Try this on for size.
Scrolling Banner This splotch of code is for your typical scrolling banner. It's not as cheesy as Internet Explorer's <marquee> tag, but it's also not as complicated as a lot of those scrolling banner Java applet's either. Warning: This is highly dorky and not recommended for actual use. I've got it here more as an example of what can happen when JavaScript falls into the wrong hands. Insert this in the <head>:
Now, add this to your <body> tag.
Finally, put this wherever you want the banner to show up and brace yourself.
Behold, dorkiness in all it's blatant glory:
Popup Windows And finally, the most powerful and dynamic feature of JavaScript (aside from my transmogrifier engines) is the ability to open up whole new browser windows and have them float around the screen. This is way cool, and you can do so much with it. There's two different ways you can do this. Both work fine and give you the same control over the new window. One just has more code to it than the other. Here's the longer code. Insert this part in your <head>.
The beauty of this is the absolute control you have over the new window. Where it says width=340,height=350,resizable=1,etc., that's where you can configure the appearance of the window. Below is a listing of the different options you can use. You can set these either to 0 or no for off, or 1 or yes for on. The default for these is on, so you don't need to put all of these in your script unless you don't want to use them.
As for your <a href=""> tag, it'll look like this:
Click below for an example idea of what this looks like.
And here's a smaller version of the code. This one is just as configurable, just shorter.
And here's your <a href="">. It's a little different from the first one in that the URL is in this tag (where in the first one it was part of the script).
Click below for an example idea of what this looks like.
The advantage of this one over the first script is that you can use this one over and over again on the same page because the URL is in the <a href=""> tag. In the first script, everytime you try to call the makeRemote() function, it's going to take you to the URL that's part of that script. One way to get around that is to change the name of the function for everytime you use it. So you could end up with a function named makeWindow or makeFloater or even biteMe. But that can get kinda messy when you try to keep track of what does what. With the second script, you just call the URL in the <a href="javascript:open_window('URL goes here')"> and you're all set.
|