Today is . Page created 12/16/06
Always On Top Popup |
X |
[You can close the layer by clicking the X at the top right of this layer.] |
This script opens a floating layer popup. This technique allows the user to work in the main window while still being able to view the popup. The popup window will hover at the same spot where it opens, even if the user scrolls down the page.
We have tested the code in IE7.0, Firefox1.5.0.7, Opera9.02, Netscape8.1 and AOL Explorer1.2. This script worked well in all platforms with no variations observed.
Depending on your knowledge of HTML and javascripts, this is an easy four (4) part copy and paste code that goes in both the <HEAD> (2 parts) and <BODY> sections of your document. It also makes use of a CSS section that goes into the <HEAD> section and an external .js script you need to save and upload into your directory then add a snipplet of code into the <HEAD> section to call the external.js file.
Since this is a four (4) part copy and paste code, we will do each secion one at a time starting with the CSS section that goes in the <HEAD> section.
The CSS section of the code that you will get from the script site tells you:
"......Paste this code into your external CSS file or in the <style> section within the <HEAD> section of your HTML document......"
This is all well and good if you have a CSS <style> section in your document. If not, it is not a problem. You just need to add the opening and closing style tags into this section of code. If this is a little confusing, See below on where and howto:
<style type="text/css">
Paste CSS Section Of Code Here!
</style>
The below is the style sheet (CSS) coding ( minus the opening and closing style tags ) that can be reconfigured. All this code does is define the colors and text position of the X (upper right corner) that is used to close the box itself.
td.top {
background-color: #000080;
text-align: right;
}
td.bottom {
background-color: #ffe38c;
padding: 15px;
}
The next step is to copy and paste a section of code into a notepad, save it as floatingLayer.js. This will be your external .js file that once you save as, you will need to upload it into your directory and then add a snipplet of code into the <HEAD> section to call the external floatingLayer.js file.
Note Of Importance: If you are not sure of howto make the external .js file and make use of it within your document, grab the below link and it is fully explained.
[ .js File Howto ]
For your Information:
If you are not comfortable or prefer not to use the external.js file, you can use the traditional cut/copy and paste instead of the external .js file. If you need a little refresher on what is required to achieve this, grab the below link and it is fully explained.
[ Traditional Cut/Copy and Paste ]
Depending on which of the above methods you have selected (external.js* file or Traditional Copy/Cut & Paste), you will add either the snipplet of code (after you have uploaded the external.js file) into the <HEAD> section or the completed section of code that you added the opening and closing script tags.
<script type="text/javascript" src="floatingLayer.js"> </script> <SCRIPT LANGUAGE="JavaScript"> <HEAD> Section of code goes here // End --> </script> |
External .js file Traditional Copy/Cut & Paste Code with opening & closing tags that you had to add into the <HEAD> section of code that was originally earmarked to be an external .js file. |
If you would like to see an example of this effect using the "Traditional Cut/Copy & Paste" method, grab the below link and you are there. Examine our "Source" code (on the page you will be opening) to see how we had to reconfigure it to make it work. We have it very well documented for your convenience.
[ Traditional Cut/Copy & Paste Method ]
The next step is that of the <BODY> section. This you can paste anywhere within the body section you want the effect to appear.*. Keep in mind that if you place this effect at the bottom of the page, no one will see it (the form button to click) when the page first opens. They will have to scroll all the way to the bottom of the page to click the button. Then it will follow the page as you scroll up towards the top.
* For your Information: You can only have one of these effects per page. If you add more, the main one or <div id="layer1" will supercede all others and the text etc. in this box will be the same for all boxes.
<div id="layer1" style="position:absolute; left:20px; width:410px; height:10px; visibility:hidden;">
<table border="0" cellspacing="0" cellpadding="3">
<tr>
<td class="top">
<a href="javascript:hideIt()" style="text-decoration: none"><font color="#ffffff"><b>X</b></font></a>
</td>
</tr>
<tr>
<td class="bottom">
Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt
ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci.
<br><br>
[<em>You can close the layer by clicking the <strong>X</strong> at the top right of this layer.</em>]
</td>
</tr>
</table>
</font>
</div>
<form>
<input type="button" value="Open popup" onClick="showIt()">
</form>
T here are four (4) different sections to this part of the code so.....We will take each part at a time.
<div id="layer1" style="position:absolute; left:20px; width:410px; height:10px; visibility:hidden;">The next part you "Must" leave in the code. You can reposition it but it must stay. This is the link that will close the popup.
<a href="javascript:hideIt()" style="text-decoration: none"><font color="#ffffff"><b>X</b></font></a>
The next part is where you will add your content. This can be text, images, links (be sure to have links open in a new window or the popup box will vanish as you click on the link). etc.
<td class="bottom">
This is where you will insert your content
</td>
</tr>
The last part of this section is the form button itself. The only reconfiguration you can really make is that of the wording on the button itself.
<form>
<input type="button" value="Open popup" onClick="showIt()">
</form>
This pertains to the style sheet CSS section we discussed earlier in this tutorial. If you would prefer to have the CSS section called from an external file,this is not a problem. Just copy and paste the css section (No opening or closing tags) into a notepad, save as popUp.css, upload it into your directory and now add a snipplet of code into the <HEAD> section of your document to call this file. In all actuality, it is the very same way you would do an external.js file except the file extension is .css and the code to call this file is slightly different. See below:
Saved .css File |
Snipplet of Code for external .css file [ Relative vs. Absolute ] |
If you would like to see thie effect with the use of an external .css file, grab the below link and you are there.
[ With External .CSS File ]
We hope our tutorial was easy to follow and we covered everything in detail. If you would like to add this effect into your pages, grab the respective below link and you are there. If you have any problems with this or anything else, feel free to consult our [ FAQ ] and if you can't find the answer there, [ contact us ].
[ Get Code Here ]
[ Rate This Page ]