Posts Tagged ‘js’

Disable Form Autocomplete

Disabling a visitor’s browser’s built-in form autocomplete feature sounds like it should be a simple enough task, but like many seemingly mundane things in web design it’s a bit asinine. I have personally never had to do this until yesterday when I made an AJAX-based autocompleting search field and realized it didn’t do much good hiding behind the browser’s. It could also be useful to avert the visitor’s autocomplete where the data shouldn’t be remembered by the browser (like credit card numbers) or re-entered for verification (like e-mail addresses).

The easiest method (and the one with which I went) is to add the

autocomplete="off"

attribute to your <form> or individual <input> tags. According to Mozilla Developer Network’s How to Turn Off Form Autocompletion:

This form attribute was first introduced in Microsoft’s Internet Explorer 5. Netscape introduced it in version 6.2 — in prior versions, this attribute is ignored. The autocomplete attribute was added at the insistance of banks and card issuers, but prior to HTML5 was never part of an official standard.

In practical terms this means the autocomplete attribute is perfectly valid and there is no good reason you shouldn’t use it. In ideological terms, unless you are using it in an HTML5 document, the attribute is not valid HTML and will fail a validation test.

Sometimes it’s OK to be a rebel. Sometimes there’s a cheat code, though. It’s possible to set this attribute in JavaScript and produce flawless HTML. There is only one drawback: those with JavaScript disabled (no one) will not be affected:

var q = document.getElementById('query');
q.autocomplete = 'off';

An alternative I thought of but rejected on the grounds that it would make untidy URLs is the use of hidden <input>s and the onchange event handler. It could work well for POSTed forms, however:

<input type="hidden" name="query" id="query">
<input type="text" name="<?php echo md5(time()); ?>" onchange="document.getElementById('query').value = this.value;">

Stream Webcams and Sound in Flash via RTMP with JW Player

WARNING A lot of folks have reported they can’t get the audio working. I dropped this method for http://code.google.com/p/flash-videoio/ and wouldn’t recomment wasting your time with jwplayer. flash-videoio has JavaScript hooks that let you configure most player/recorder settings on-the-fly which has huge potential when mixed with AJAX.

JW Player is a popular extensible flash (now also available in HTML5) video player. Until versions 4.5 and up it supported grabbing video and audio sources locally attached to the client machine and publishing them to a streaming server (like Flash Media Server, Red5 or C++ RTMP Server) via RTMP. This feature was abandoned due to inherent limitations of the built-in encoding capabilities of Flash Player vs. stand-alone encoding software like Flash Live Media Encoder. This situation doesn’t suit everyone however; in a video conferencing scenario users must be able to connect with as little hassle as possible and forcing them to download specialized software presents a significant enough accessibility barrier to warrant swallowing the quality losses associated with Flash Player encoding.

Using version 4.4.198 available at http://developer.longtailvideo.com/trac/browser/tags/mediaplayer-4.4?rev=885, an RTMP server and the latest version of JW Player (available here) we will make a simple broadcast and view page. Extract the contents of these archives to jwpublisher/ and jwplayer/ respectively.

Let rtmp://xxx.xxx.xxx.xxx/live be the URI to your working FMS/Red5/C++ RTMP Server application and livestream be the name of our stream. Create an index.html in jwpublisher/ to reflect:

<html lang="en">
  <head>
    <script src="swfobject.js"></script>
    <script type="text/javascript">
      var flashvars =
      {
        'streamer':                     'rtmp://xxx.xxx.xxx.xxx/live',
        'file':                         'livestream',
        'type':                         'camera',
        'controlbar':                   'bottom',
        'stretching':                   'none',
        'frontcolor':                   '86C29D',  // text & icons                  (green)
        'backcolor':                    '849BC1',  // playlist background           (blue)
        'lightcolor':                   'C286BA',  // selected text/track highlight (pink)
        'screencolor':                  'FFFFFF',  // screen background             (black)
        'id':                           'playerID',
        'autostart':                    'true'
      };

      var params =
      {
        'allowfullscreen':              'true',
        'allowscriptaccess':            'always',
        'bgcolor':                      '#FFFFFF'
      };

      var attributes =
      {
        'id':                           'playerID',
        'name':                         'playerID'
      };
      swfobject.embedSWF('player.swf', 'player', '320', '260', '9.0.124', false, flashvars, params, attributes);
    </script>
  </head>
  <body>
    <div id="playercontainer" class="playercontainer"><a id="player" class="player" href="http://get.adobe.com/flashplayer/">Get the Adobe Flash Player to see this video.</a></div>
  </body>
</html> 

Now create an index.html in jwplayer/:

<html>
<head>
<script type='text/javascript' src='jwplayer.js'></script>
</head>
<body>
<div id='mediaspace'>This text will be replaced</div>
<script type='text/javascript'>
  jwplayer('mediaspace').setup({
    'flashplayer': 'player.swf',
    'type': 'rtmp',
    'streamer': 'rtmp://xxx.xxx.xxx.xxx/live',
    'autostart': 'true',
    'bufferlength': '3,
    'file': 'livestream',
    'controlbar': 'none',
    'width': '320',
    'height': '260'
  });
</script>
</body>
</html>

Load jwpublisher/ in your browser. Flash will ask for access to your webcam if it can find one. Once the video appears load jwplayer/ and allow a few seconds for buffering. If your streaming server works you should now be watching a slightly delayed version of the video being captured from your webcam.

Return top
foxpa.ws
Online Marketing Toplist
Internet
Technology Blogs - Blog Rankings

Internet Blogs - BlogCatalog Blog Directory

Technology blogs
Bad Karma Networks

Please Donate!


Made in Canada  •  There's a fox in the Gibson!  •  2010-12