|
|
We'll begin by modifying the basic popup script from our first example. The following script is similar to the first example, but with one important difference: before directing the popup to a URL the script first checks if the popup is already at that URL. If the popup is already at the URL then no action is taken:
<SCRIPT TYPE="text/javascript">
<!--
function popupnr(mylink, windowname, refocus)
{
var mywin, href;
if (typeof(mylink) == 'string')
href=mylink;
else
href=mylink.href;
mywin = window.open('', windowname, 'width=400,height=200,scrollbars=yes');
// if we just opened the window
if (
mywin.closed ||
(! mywin.document.URL) ||
(mywin.document.URL.indexOf("about") == 0)
)
mywin.location=href;
else if (refocus)
mywin.focus();
return false;
}
//-->
</SCRIPT>
Use this script in the same way as in our first example. Call popupnr() in the onClickthis, meaning the link object itself, and the second argument is a unique name for the popup. For example, this link opens a popup that plays some
background music. The music keeps playing uninterrupted even when you click on the link several times:
<A HREF="nrl.html" onClick="return popupnr(this, 'music')">music</A>
which gives us this link:
Try clicking on the link and then, without closing the popup, come back to this page and click on the link again. On the second click nothing changes: the popup stays in the back and the music keeps playing uninterrupted.
www.idocs.com, don't attempt to load a popup with a page from
www.ninthwonder.com. For security reasons JavaScript cannot read the URL information for sites outside the domain of the current web site.
true as a third argument to popupnr():
<A HREF="nrl.html" onClick="return popupnr(this, 'music',true)">music</A>
which gives us this link:
You can also use this script to open popups automatically. Call popupnr() in the
onLoad
| this code | produces this |
<BODY onLoad="return popupnr('nrl.html', 'music')">
|
this page |
|
Recommended Resources |
|||
| web hosting tutorials Credit Help |
Search the Internet Search Engine Help |
Low Fat Lifestyle Internet Traffic |
Web
Hosting Web Design |
|
Discount
Hotel Reservations All
Rights Reserved, Copyright © Free-HTML-Tutorials.com 2003 |
|||