Some Useful JavaScript Tricks

Written by Mitchell Harper


JavaScript can be one ofrepparttar most useful additions to any web page. It comes bundled with Microsoft Internet Explorer and Netscape Navigator and it allows us to perform field validations, mouse-overs images, open popup windows, and a slew of other things.

In this article I will show you how to:

- Displayrepparttar 105601 browser name and version number - Changerepparttar 105602 text inrepparttar 105603 status bar ofrepparttar 105604 browser - Use an input box to get text fromrepparttar 105605 user - Use a message box to display text torepparttar 105606 user - Changerepparttar 105607 title ofrepparttar 105608 browser window

Before that, however, we need to know how to setup our web page so that it can runrepparttar 105609 JavaScript. JavaScript code is inserted between opening and closing script tags: , like this:

These script tags can be placed anywhere onrepparttar 105610 page, however it's common practice to place them betweenrepparttar 105611 and tags. A basic HTML page that contains some JavaScript looks like this:

My Test Page < itle> <script language="JavaScript"><p> function testfunc() { var x = 1; }<p></script> </head> <body> <h1>Hello</h1> </body> </html><p>For<IMG height=12 src="/the2.jpg" alt="repparttar 105612"> examples in this article, you should use<IMG height=12 src="/the2.jpg" alt="repparttar 105613"> basic document format I have just shown you, inserting<IMG height=12 src="/the2.jpg" alt="repparttar 105614"> JavaScript code between<IMG height=12 src="/the2.jpg" alt="repparttar 105615"> <script> and </script> tags. When you load<IMG height=12 src="/the2.jpg" alt="repparttar 105616"> page in your browser,<IMG height=12 src="/the2.jpg" alt="repparttar 105617"> JavaScript code will be executed automatically.<p>----------------------------------------------- Displaying<IMG height=12 src="/the2.jpg" alt="repparttar 105618"> browsers name and version number -----------------------------------------------<p>The "navigator" object in JavaScript contains<IMG height=12 src="/the2.jpg" alt="repparttar 105619"> details of<IMG height=12 src="/the2.jpg" alt="repparttar 105620"> users browser, including its name and version number. We can display them in our browser using<IMG height=12 src="/the2.jpg" alt="repparttar 105621"> document.write function:<p> document.write("Your browser is: " + navigator.appName); document.write(" Its version is: " + navigator.appVersion);<p>I run Windows 2000 and Internet Explorer version 6, so<IMG height=12 src="/the2.jpg" alt="repparttar 105622"> output from<IMG height=12 src="/the2.jpg" alt="repparttar 105623"> code above looks like this in my browser window:<p> Your browser is: Microsoft Internet Explorer Its version is: 4.0 (compatible; MSIE 6.0b; Windows NT 5.0)<p>----------------------------------------------- Changing<IMG height=12 src="/the2.jpg" alt="repparttar 105624"> text in<IMG height=12 src="/the2.jpg" alt="repparttar 105625"> status bar of<IMG height=12 src="/the2.jpg" alt="repparttar 105626"> browser ----------------------------------------------- <br><br></font></td><!-- google_ad_section_end --><!-- google_ad_section_start(weight=ignore) --><td align="top" width="10%"></td><td align="top" width="45%"><h2>Grow Your Subscribers Exponentially With These Javascript E-mail Capture Boxes!</h2><font size="2">Written by Vishal Rao</font><br><br><script type="text/javascript"><!-- google_ad_client = "pub-5766870852072819"; google_ad_width = 234; google_ad_height = 60; google_ad_format = "234x60_as"; google_ad_channel ="9238851329"; google_color_border = "CFB9A1"; google_color_bg = "CFB9A1"; google_color_link = "000000"; google_color_url = "431B02"; google_color_text = "431B02"; //--></script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> <br> <font size="2">Here's an exciting pop-up tactic that can literally boost<IMG height=12 src="/the2.jpg" alt="repparttar "> no. of opt-ins from your existing traffic. In fact<IMG height=12 src="/the2.jpg" alt="repparttar 105600"> first one to use this tactic is by<IMG height=12 src="/the2.jpg" alt="repparttar 105601"> very successful list management/autoresponder tool - OptinLightning.<p>I love my list management tool - Aweber, and wanted to use a similar E-mail Capture box like OptinLightning to go with it.<p>To see exactly how this E-mail Capture box works, just visit: http://www.raovishal.com/milliondollar<p>Now this might be annoying to quite a few but when highly successful marketers like Terry Dean have claimed that their subscribers have increased by almost 25% from using this E-mail Capture boxes at his web site, this tactic is worth giving a try.<p>The only requirement you need to use this tactic for your list is that your list should have a subscribe e-mail address. Which means that someone should be able to subscribe to your list by send an e-mail.<p>OK, now coming back to creating<IMG height=12 src="/the2.jpg" alt="repparttar 105602"> code, create a file named subscribe.js. Visit<IMG height=12 src="/the2.jpg" alt="repparttar 105603"> following URL and paste<IMG height=12 src="/the2.jpg" alt="repparttar 105604"> code in it to your subscribe.js file:<p>http://www.raovishal.com/articles/jeccode.txt<p>Upload<IMG height=12 src="/the2.jpg" alt="repparttar 105605"> subscribe.js file to your web server in ASCII mode.<p>Here's what this code does:<p>Everything that comes between 'if (confirm("' and ')){' will be displayed in<IMG height=12 src="/the2.jpg" alt="repparttar 105606"> E-mail Capture box.<p>' ' is<IMG height=12 src="/the2.jpg" alt="repparttar 105607"> newline character. Which means anything after ' ' will come in<IMG height=12 src="/the2.jpg" alt="repparttar 105608"> next line. '<p>' means a blank line and then<IMG height=12 src="/the2.jpg" alt="repparttar 105609"> next line. Simple, isn't it?<p>You can change<IMG height=12 src="/the2.jpg" alt="repparttar 105610"> text in<IMG height=12 src="/the2.jpg" alt="repparttar 105611"> above code to reflect your newsletter and bonuses.<p>Now to display<IMG height=12 src="/the2.jpg" alt="repparttar 105612"> E-mail Capture box in any page you like, you need to do<IMG height=12 src="/the2.jpg" alt="repparttar 105613"> following.<p>Include<IMG height=12 src="/the2.jpg" alt="repparttar 105614"> following code in<IMG height=12 src="/the2.jpg" alt="repparttar 105615"> HEAD section of your html code: <br><br></font></td><!-- google_ad_section_end --></tr><tr><td>Cont'd on page 2 ==<a class="mlink" href="2-Some_Useful_JavaScript_Tricks-5601.htm">></a></td></tr></table><script type="text/javascript"><!-- google_ad_client = "pub-5766870852072819"; google_ad_width = 728; google_ad_height = 90; google_ad_format = "728x90_as"; google_ad_channel ="8831454965"; google_color_border = "CFB9A1"; google_color_bg = "CFB9A1"; google_color_link = "000000"; google_color_url = "431B02"; google_color_text = "431B02"; //--></script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> </td> </tr> </table> <table width="770" border="0" cellspacing="0" cellpadding="0"> <tr> <td> </td> </tr> <tr> <td height="48" align="center" background="images/bg_nav_bottm.jpg"><span class="style3">ImproveHomeLife.com © 2005<br> <a href="terms.html" rel="nofollow">Terms of Use</a></span></td> </tr> </table></td> </tr> </table> <script type="text/javascript"> var HASH_ESCAPED="%23"; function TrackIt(adUnit){ if (window.status) { var adDomain = escape(window.status.substring(6)); var pyPage = document.location.pathname; var params = document.location.search; var hasAnchor = params.lastIndexOf(HASH_ESCAPED)!= -1; params = hasAnchor? (params.substring(0, params.lastIndexOf(HASH_ESCAPED))) : params; pyPage = escape(pyPage.substring(pyPage.lastIndexOf('/') + 1)); pyPage = pyPage + params; var curTime = new Date().valueOf(); var bug = new Image(); bug.src = '/track/adsenseTrack.php?pyPage=' + pyPage + '&adDomain=' + adDomain + '&adUnit=' + adUnit + "&time=" + curTime; } } function TrackIt0() {TrackIt(0); } function TrackIt1() {TrackIt(1); } function TrackIt2() {TrackIt(2); } var elements = document.getElementsByTagName("iframe"); for (var i = 0; i < elements.length; i++) { if(elements[i].src.indexOf('googlesyndication.com') > -1) { //elements[i].onfocus = TrackIt; if (i==0) elements[i].onfocus = TrackIt0; if (i==1) elements[i].onfocus = TrackIt1; if (i==2) elements[i].onfocus = TrackIt2; } } </script> <!--WEBBOT bot="HTMLMarkup" startspan ALT="Site Meter" --> <script type="text/javascript" language="JavaScript">var site="s19improve"</script> <script type="text/javascript" language="JavaScript1.2" src="http://s19.sitemeter.com/js/counter.js?site=s19improve"> </script> <noscript> <a href="http://s19.sitemeter.com/stats.asp?site=s19improve" target="_top"> <img src="http://s19.sitemeter.com/meter.asp?site=s19improve" alt="Site Meter" border=0></a> </noscript> <!-- Copyright (c)2002 Site Meter --> <!--WEBBOT bot="HTMLMarkup" Endspan --> </body> </html>