Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #25484

Re: Images and pdf in a div

From danca <cyberdanny@tiscalinet.it>
Newsgroups comp.lang.javascript
Subject Re: Images and pdf in a div
Date 2014-07-20 20:07 +0200
Organization A noiseless patient Spider
Message-ID <lqh0h0$to7$1@dont-email.me> (permalink)
References (2 earlier) <lqds4k$iad$1@dont-email.me> <XnsA36FA164733A9eejj99@194.109.133.133> <lqe6fa$sid$1@dont-email.me> <m_CdnTCZ5NKWzlbOnZ2dnUVZ_tGdnZ2d@westnet.com.au> <2221038.iVyETpmlb9@PointedEars.de>

Show all headers | View raw


Il 20/07/2014 12:42, Thomas 'PointedEars' Lahn ha scritto:
> Andrew Poulos wrote:
>
>> How about changing the code to something like:
>>
>> var AcrobatInfo = (function() {
>
> Not a constructor; by convention, the name should start lowercase.
> Preferably, you would put it in a private namespace, like
> “ap.acrobatInfo”. Creating a user-defined object that would retrieve
> the information about all plugins, and then would allow to retrieve
> information for a specific plugin, is indicated.
>
>> var isInstalled = false, vern = null;
>>
>> function findPlugin(nme) { var p; for (key in navigator.plugins) {
>
> Do not use the for-in statement with host objects and array-like
> objects; their properties may not be enumerable, not in a defined
> order or have enumerable properties that you do not want to iterate
> over (like “refresh”); use the “for” statement instead.  Exception:
> Array instances known to encapsulate a sparse array; in that case
> for-in is more efficient, and you can filter and sort the properties
> later, if necessary.
>
> You have not declared “key”; this code will throw a ReferenceError
> exception in strict mode.
>
>> […] (function() { var plugin;
>>
>> if (typeof window.ActiveXObject != "undefined") {
>
> Check the “ActiveXObject” property of the global object instead.
>
>> // AcroPDF.PDF is used by version 7 and later // PDF.PdfCtrl is
>> used by version 6 and earlier
>
> You should use multi-line comments for documentation instead, in
> order to be able to tell them apart from deactivating comments
> easily.
>
>> try { plugin = new ActiveXObject("AcroPDF.PDF"); isInstalled =
>> true; } catch(e) {} try { plugin = new
>> ActiveXObject("PDF.PdfCtrl"); isInstalled = true; } catch(e) {}
>
> You should nest those try-catch blocks, leaving at most one empty
> “catch” block.
>
> “isInstalled” is superfluous because you can test against the value
> of “plugin” instead, which would be either not “null” or not
> “undefined” if successful, depending on how you initialize it.
>
>> })(); […] })();
>
> I suggest you always use the same indentation for opening and
> closing delimiters.
>
> And “}())” instead in order to make clear what makes up the
> right-hand side expression.  This will also become handy in editors
> like Vim or Eclipse JSDT with Vrapper plugin, where, which I
> discovered yesterday, you can type “vi)” to select everything between
> the outer parentheses, for refactoring.
>
>
Uhm... something like this?
getInfo={}
getInfo.acrobatInfo = (function() { var vern = null;
function findPlugin(nme) { var p;
for (var key=0; key<navigator.plugins.length; ++key) {
p = navigator.plugins[key];
if (p.name == nme) return p; }
return  null; }
(function() { var plugin;
if (typeof ActiveXObject != "undefined") { /* AcroPDF.PDF is used by 
version 7 and later - PDF.PdfCtrl is used by version 6 and earlier*/
try { plugin = new ActiveXObject("AcroPDF.PDF")}
catch(e) { try { plugin = new ActiveXObject("PDF.PdfCtrl")}
catch(e) {}
}
if (plugin) { vern = plugin.GetVersions().split(',')[0].split('=')[1]; }
} else { plugin = findPlugin('Adobe Acrobat') || findPlugin('Chrome PDF 
Viewer') || findPlugin('WebKit built-in PDF');
if (plugin && plugin.version) vern = plugin.version; }
plugin = null; })();
return { installed: vern!=null, version: vern }; })();


Usage

var a = "Acrobat is " + (getInfo.acrobatInfo.installed?"":"not") + 
"installed. " + getInfo.acrobatInfo.version||"";

Many thanks.
I tested in FF, Konqueror and IE 8/9 and it seems to work, (ok I don't 
have Acrobat plugin installed in Konqueror so it's unclear). In IE 8 it 
truncates the version number, and in Opera 12.16 and Safari 5.1.7 the 
plugin is not detected.
Dan

Back to comp.lang.javascript | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Images and pdf in a div danca <cyberdanny@tiscalinet.it> - 2014-07-19 00:31 +0200
  Re: Images and pdf in a div "Christoph M. Becker" <cmbecker69@arcor.de> - 2014-07-19 13:34 +0200
    Re: Images and pdf in a div danca <cyberdanny@tiscalinet.it> - 2014-07-19 15:34 +0200
      Re: Images and pdf in a div "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-07-19 15:51 +0200
        Re: Images and pdf in a div danca <cyberdanny@tiscalinet.it> - 2014-07-19 18:30 +0200
          Re: Images and pdf in a div Andrew Poulos <ap_prog@hotmail.com> - 2014-07-20 15:23 +1000
            Re: Images and pdf in a div Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-07-20 12:42 +0200
              Re: Images and pdf in a div danca <cyberdanny@tiscalinet.it> - 2014-07-20 20:07 +0200
                Re: Images and pdf in a div Andrew Poulos <ap_prog@hotmail.com> - 2014-07-21 14:10 +1000
                Re: Images and pdf in a div danca <cyberdanny@tiscalinet.it> - 2014-07-21 14:19 +0200
              Re: Images and pdf in a div Andrew Poulos <ap_prog@hotmail.com> - 2014-07-21 08:14 +1000
                Re: Images and pdf in a div Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-07-21 02:00 +0200
                Re: Images and pdf in a div "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-07-21 07:15 +0200
                Re: Images and pdf in a div Osmo Saarikumpu <osmo@weppipakki.com> - 2014-07-24 18:26 +0300
                Re: Images and pdf in a div "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-07-24 17:48 +0200
                Re: Images and pdf in a div Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-07-24 22:32 +0100
                Re: Images and pdf in a div "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-07-24 23:58 +0200
                Re: Images and pdf in a div "Christoph M. Becker" <cmbecker69@arcor.de> - 2014-07-24 18:40 +0200
                Re: Images and pdf in a div Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-07-25 12:31 +0200
                Re: Images and pdf in a div John Harris <niam@jghnorth.org.uk.invalid> - 2014-07-25 15:52 +0100

csiph-web