[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.javascript

Images and pdf in a div

danca

7/18/2014 10:31:00 PM

Hi all,
I have a page with thumbnails. When the user clicks on a thumbnail a
script does the following:
- creates a div
- populates the div with some buttons (next,previous, close, change
resolution...)
-creates a image node, sets src to the big image the thumbnail
correspond to, ad inserts it in the div
- finally appends the div to document.
So far, so good.
When the thumbnails points to a PDF, however, I have to change the div,
particularly I:
-create a new embed node
-use replaceChild to switch the node image with the newly created node
embed.
I could anyway go another route:
create the two nodes and simply give display:none to alternatively the
image and the embed node, without the use of replaceChild.

Has someone an idea about cross-browsers issues with the first approach?
It works with all the (main, modern) browsers on a pc. Android browser
is OK too, but I'm unsure about iPads and iPhones (and I have no one to
test with).
Thanks
Dan
19 Answers

Christoph M. Becker

7/19/2014 11:34:00 AM

0

danca wrote:

> When the thumbnails points to a PDF, however, I have to change the div,
> particularly I:
> -create a new embed node
> -use replaceChild to switch the node image with the newly created node
> embed.
> I could anyway go another route:
> create the two nodes and simply give display:none to alternatively the
> image and the embed node, without the use of replaceChild.
>
> Has someone an idea about cross-browsers issues with the first approach?
> It works with all the (main, modern) browsers on a pc. Android browser
> is OK too, but I'm unsure about iPads and iPhones (and I have no one to
> test with).

I don't see any problems regarding the replacement of the node (i.e.
your first approach).

However, the embed element surely requires a PDF reader/renderer to be
available in the browser (e.g. the Adobe Acrobat plugin). If that is
not available, the browser likely will render an empty space or maybe an
error message. Perhaps it is reasonable to display a preview image
instead of the PDF document.

--
Christoph M. Becker

danca

7/19/2014 1:34:00 PM

0

Il 19/07/2014 13:34, Christoph M. Becker ha scritto:
> danca wrote:
>
>> When the thumbnails points to a PDF, however, I have to change the div,
>> particularly I:
>> -create a new embed node
>> -use replaceChild to switch the node image with the newly created node
>> embed.
>> I could anyway go another route:
>> create the two nodes and simply give display:none to alternatively the
>> image and the embed node, without the use of replaceChild.
>>
>> Has someone an idea about cross-browsers issues with the first approach?
>> It works with all the (main, modern) browsers on a pc. Android browser
>> is OK too, but I'm unsure about iPads and iPhones (and I have no one to
>> test with).
>
> I don't see any problems regarding the replacement of the node (i.e.
> your first approach).
>
> However, the embed element surely requires a PDF reader/renderer to be
> available in the browser (e.g. the Adobe Acrobat plugin). If that is
> not available, the browser likely will render an empty space or maybe an
> error message. Perhaps it is reasonable to display a preview image
> instead of the PDF document.
>
It is unclear to me how to detect preliminarly the availability of the
plugin, or which syntax to use to have a fallback to a preview image.
I am a bit puzzled with this idea, it sounds good but I would greatly
appreciate a hint.
My basic code is something like this:
....
var oldNode=document.getElementById("doc")
var newNode=document.createElement("embed")
newNode.type="application/pdf"
newNode.src="http://"+location.host+"/images/test.pdf"
oldNode.parentNode.replaceChild(newNode,oldNode)
newNode.id="doc" // ready for another substitution - same id as previous
....
then I resize the div container etc.
So... what kind of feature must I look for?
Many thanks
Dan

Evertjan.

7/19/2014 1:52:00 PM

0

danca <cyberdanny@tiscalinet.it> wrote on 19 jul 2014 in
comp.lang.javascript:

> Il 19/07/2014 13:34, Christoph M. Becker ha scritto:
>> danca wrote:
>>
>>> When the thumbnails points to a PDF, however, I have to change the div,
>>> particularly I:
>>> -create a new embed node
>>> -use replaceChild to switch the node image with the newly created node
>>> embed.
>>> I could anyway go another route:
>>> create the two nodes and simply give display:none to alternatively the
>>> image and the embed node, without the use of replaceChild.
>>>
>>> Has someone an idea about cross-browsers issues with the first approach?
>>> It works with all the (main, modern) browsers on a pc. Android browser
>>> is OK too, but I'm unsure about iPads and iPhones (and I have no one to
>>> test with).
>>
>> I don't see any problems regarding the replacement of the node (i.e.
>> your first approach).
>>
>> However, the embed element surely requires a PDF reader/renderer to be
>> available in the browser (e.g. the Adobe Acrobat plugin). If that is
>> not available, the browser likely will render an empty space or maybe an
>> error message. Perhaps it is reasonable to display a preview image
>> instead of the PDF document.
>>
> It is unclear to me how to detect preliminarly the availability of the
> plugin, or which syntax to use to have a fallback to a preview image.
> I am a bit puzzled with this idea, it sounds good but I would greatly
> appreciate a hint.
> My basic code is something like this:
> ...
> var oldNode=document.getElementById("doc")
> var newNode=document.createElement("embed")
> newNode.type="application/pdf"
> newNode.src="http://"+location.host+"/images/test.pdf"
> oldNode.parentNode.replaceChild(newNode,oldNode)
> newNode.id="doc" // ready for another substitution - same id as previous
> ...
> then I resize the div container etc.
> So... what kind of feature must I look for?

Google is your friend, I hope:

<http://thecodeabode.blogspot.nl/2011/01/detect-adobe-reader-plugi...

I did not test this, btw.


--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

danca

7/19/2014 4:31:00 PM

0

Il 19/07/2014 15:51, Evertjan. ha scritto:
> danca <cyberdanny@tiscalinet.it> wrote on 19 jul 2014 in
> comp.lang.javascript:
>
>> Il 19/07/2014 13:34, Christoph M. Becker ha scritto:
....
>>>
>>> I don't see any problems regarding the replacement of the node (i.e.
>>> your first approach).
>>>
>>> However, the embed element surely requires a PDF reader/renderer to be
>>> available in the browser (e.g. the Adobe Acrobat plugin). If that is
>>> not available, the browser likely will render an empty space or maybe an
>>> error message. Perhaps it is reasonable to display a preview image
>>> instead of the PDF document.
>>>
>> It is unclear to me how to detect preliminarly the availability of the
>> plugin, or which syntax to use to have a fallback to a preview image.
>> I am a bit puzzled with this idea, it sounds good but I would greatly
>> appreciate a hint.
>> My basic code is something like this:
>> ...
>> var oldNode=document.getElementById("doc")
>> var newNode=document.createElement("embed")
>> newNode.type="application/pdf"
>> newNode.src="http://"+location.host+"/images/test.pdf"
>> oldNode.parentNode.replaceChild(newNode,oldNode)
>> newNode.id="doc" // ready for another substitution - same id as previous
>> ...
>> then I resize the div container etc.
>> So... what kind of feature must I look for?
>
> Google is your friend, I hope:
>
> <http://thecodeabode.blogspot.nl/2011/01/detect-adobe-reader-plugi...
>
> I did not test this, btw.
>
I feared an answer like this. Thanks, no.

(excerpt)

var getBrowserName = function() {
return this.name = this.name || function() {
var userAgent = navigator ? navigator.userAgent.toLowerCase() :
"other";

if(userAgent.indexOf("chrome") > -1) return "chrome";
else if(userAgent.indexOf("safari") > -1) return "safari";
else if(userAgent.indexOf("msie") > -1) return "ie";
else if(userAgent.indexOf("firefox") > -1) return "firefox";
return userAgent;

ugh.
btw weren't we all negative about browser sniffing? I'm doing my best to
follow best practices and this NG is a big resource in this matter.
(Still learning, as all my life is about).

Uhm no, I'll not support people not able to correctly display a pdf in
their browser. They can download the file and see it offline.

Apart the fact that this all is about a CMS-like system, the script part
being a fragment of the total, the publisher decides what to publish and
his audience, so if one comes and has no pdf support it is not my
problem at the end of the tale, if not in a very indirect way.

Anyway I hope my question is of interest for someone else.
When it comes to "particular" questions this is the only place to go.
Thanks!
Dan

Andrew Poulos

7/20/2014 5:24:00 AM

0

On 20/07/2014 2:30 AM, danca wrote:
> Il 19/07/2014 15:51, Evertjan. ha scritto:

>> <http://thecodeabode.blogspot.nl/2011/01/detect-adobe-reader-plugi...
>>
>> I did not test this, btw.
>>
> I feared an answer like this. Thanks, no.
>
> (excerpt)
>
> var getBrowserName = function() {
> return this.name = this.name || function() {
> var userAgent = navigator ? navigator.userAgent.toLowerCase() :
> "other";
>
> if(userAgent.indexOf("chrome") > -1) return "chrome";
> else if(userAgent.indexOf("safari") > -1) return "safari";
> else if(userAgent.indexOf("msie") > -1) return "ie";
> else if(userAgent.indexOf("firefox") > -1) return "firefox";
> return userAgent;
>
> ugh.

How about changing the code to something like:

var AcrobatInfo = (function() {
var isInstalled = false,
vern = null;

function findPlugin(nme) {
var p;
for (key in navigator.plugins) {
p = navigator.plugins[key];
if (p.name == nme) return p;
}
return null;
}

(function() {
var plugin;

if (typeof window.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");
isInstalled = true;
} catch(e) {}
try {
plugin = new ActiveXObject("PDF.PdfCtrl");
isInstalled = true;
} 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) isInstalled = true;
if (plugin && plugin.version) vern = plugin.version;
}
plugin = null;
})();

return {
installed: isInstalled,
version: vern
};
})();


Usage

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

One shortcoming is that while FF will return the full version string (eg
10.1.7.27) IE 9 only returns part of the version string (eg 10.1.)

Andrew Poulos

Thomas 'PointedEars' Lahn

7/20/2014 10:43:00 AM

0

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.

--
PointedEars
FAQ: <http://PointedEars.... | SVN: <http://PointedEars.de...
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-...
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

danca

7/20/2014 6:07:00 PM

0

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

Andrew Poulos

7/20/2014 10:14:00 PM

0

On 20/07/2014 8:42 PM, Thomas 'PointedEars' Lahn wrote:
> 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.

Yes, you're right.

>> 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.

How do I search through navigator.plugins using "for" instead of "for-in"?

> You have not declared â??keyâ?; this code will throw a ReferenceError exception
> in strict mode.

Dang, I missed it.

>> [â?¦]
>> (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.

Ok.

> â??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.

After searching for "plugin" I set it to null to clear any memory...

>> })();
>> [â?¦]
>> })();
>
> I suggest you always use the same indentation for opening and closing
> delimiters.

Hmm, I think its a typo.

> 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.

Ok,
<http://dmitrysoshnikov.com/ecmascript/chapter-5-functions/#question-about-surrounding-paren...
says that both are correct so I just picked the first one.

Thanks for the advice.

Andrew Poulos

Thomas 'PointedEars' Lahn

7/21/2014 12:01:00 AM

0

Andrew Poulos wrote:

> On 20/07/2014 8:42 PM, Thomas 'PointedEars' Lahn wrote:
>> Andrew Poulos wrote:
>>> 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.
>
> How do I search through navigator.plugins using "for" instead of "for-in"?

for (var i = 0, plugins = navigator.plugins, len = plugins.length;
i < len; ++i)
{
â?¦ plugins[i] â?¦
}

(One of the properties you get when you use for-in is the â??lengthâ? property
from which you could have inferred that.)

>> â??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.
>
> After searching for "plugin" I set it to null to clear any memory...

Unnecessary if you do not return it, may even be harmful.

>> 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.
>
> Ok,
> <http://dmitrysoshnikov.com/ecmascript/chapter-5-functions/#question-about-surrounding-paren...
> says that both are correct so I just picked the first one.

Where you put the parantheses in this case is a matter of code style.

However, there are several factually wrong or misleading statements in that
text. I find it interesting that someone who has demonstrated here
(approximately at the time of writing that article, or shortly after) that
he neither understood ECMAScript nor that he was willing to learn, now
thinks he can teach others about it. I find it even more interesting that
some people believe those statements as if he would be some kind of
authority on the subject.

> Thanks for the advice.

Youâ??re welcome.

--
PointedEars
FAQ: <http://PointedEars.... | SVN: <http://PointedEars.de...
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-...
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

Andrew Poulos

7/21/2014 4:11:00 AM

0

On 21/07/2014 4:07 AM, danca wrote:
> 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.

It truncates the version in Chrome as well.

It works for me in Opera 22 and Safari 5 (under Windows) but to get the
version in Safari 5 I parsed plugin.description as plugin.version didn't
seem to exist.

Andrew Poulos