Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #25467 > unrolled thread
| Started by | danca <cyberdanny@tiscalinet.it> |
|---|---|
| First post | 2014-07-19 00:31 +0200 |
| Last post | 2014-07-25 15:52 +0100 |
| Articles | 20 — 8 participants |
Back to article view | Back to comp.lang.javascript
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
| From | danca <cyberdanny@tiscalinet.it> |
|---|---|
| Date | 2014-07-19 00:31 +0200 |
| Subject | Images and pdf in a div |
| Message-ID | <lqc77u$ljp$1@dont-email.me> |
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
[toc] | [next] | [standalone]
| From | "Christoph M. Becker" <cmbecker69@arcor.de> |
|---|---|
| Date | 2014-07-19 13:34 +0200 |
| Message-ID | <lqdl2u$45o$1@solani.org> |
| In reply to | #25467 |
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
[toc] | [prev] | [next] | [standalone]
| From | danca <cyberdanny@tiscalinet.it> |
|---|---|
| Date | 2014-07-19 15:34 +0200 |
| Message-ID | <lqds4k$iad$1@dont-email.me> |
| In reply to | #25475 |
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
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2014-07-19 15:51 +0200 |
| Message-ID | <XnsA36FA164733A9eejj99@194.109.133.133> |
| In reply to | #25477 |
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-plugin.html>
I did not test this, btw.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | danca <cyberdanny@tiscalinet.it> |
|---|---|
| Date | 2014-07-19 18:30 +0200 |
| Message-ID | <lqe6fa$sid$1@dont-email.me> |
| In reply to | #25478 |
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-plugin.html>
>
> 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
[toc] | [prev] | [next] | [standalone]
| From | Andrew Poulos <ap_prog@hotmail.com> |
|---|---|
| Date | 2014-07-20 15:23 +1000 |
| Message-ID | <m_CdnTCZ5NKWzlbOnZ2dnUVZ_tGdnZ2d@westnet.com.au> |
| In reply to | #25480 |
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-plugin.html>
>>
>> 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
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2014-07-20 12:42 +0200 |
| Message-ID | <2221038.iVyETpmlb9@PointedEars.de> |
| In reply to | #25481 |
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.de/faq> | SVN: <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix>
Please do not Cc: me. / Bitte keine Kopien per E-Mail.
[toc] | [prev] | [next] | [standalone]
| From | danca <cyberdanny@tiscalinet.it> |
|---|---|
| Date | 2014-07-20 20:07 +0200 |
| Message-ID | <lqh0h0$to7$1@dont-email.me> |
| In reply to | #25483 |
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
[toc] | [prev] | [next] | [standalone]
| From | Andrew Poulos <ap_prog@hotmail.com> |
|---|---|
| Date | 2014-07-21 14:10 +1000 |
| Message-ID | <4tudnfCg5aTuDlHOnZ2dnUVZ_rydnZ2d@westnet.com.au> |
| In reply to | #25484 |
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
[toc] | [prev] | [next] | [standalone]
| From | danca <cyberdanny@tiscalinet.it> |
|---|---|
| Date | 2014-07-21 14:19 +0200 |
| Message-ID | <lqj0hi$2tp$1@dont-email.me> |
| In reply to | #25492 |
Il 21/07/2014 06:10, Andrew Poulos ha scritto: > On 21/07/2014 4:07 AM, danca wrote: >> 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 > Ah...Ok for Safari, I had no time to investigate further, Opera 22 is similar to Chrome, AFAIK, while Opera 12.16 is the last one with Presto, a different beast. It should use the same plugin as Firefox, so for now it's unclear. Not that important: probably nobody uses Opera 12 anymore, except me ans a few other dinosaurs. But Opera mini should be still alive, I didn't test any mobile device. THX, Dan
[toc] | [prev] | [next] | [standalone]
| From | Andrew Poulos <ap_prog@hotmail.com> |
|---|---|
| Date | 2014-07-21 08:14 +1000 |
| Message-ID | <Zf2dnfu0HYh7olHOnZ2dnUVZ_gqdnZ2d@westnet.com.au> |
| In reply to | #25483 |
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-parentheses>
says that both are correct so I just picked the first one.
Thanks for the advice.
Andrew Poulos
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2014-07-21 02:00 +0200 |
| Message-ID | <3966722.Cq8BDrRF97@PointedEars.de> |
| In reply to | #25487 |
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-parentheses>
> 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.de/faq> | SVN: <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix>
Please do not Cc: me. / Bitte keine Kopien per E-Mail.
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2014-07-21 07:15 +0200 |
| Message-ID | <XnsA37149E4C23C3eejj99@194.109.133.133> |
| In reply to | #25488 |
Thomas 'PointedEars' Lahn <PointedEars@web.de> wrote on 21 jul 2014 in comp.lang.javascript: > for (var i = 0, plugins = navigator.plugins, len = plugins.length; > i < len; ++i) Some semantic plugging-in: , var plugins = navigator.plugins, var len = plugins.length; methinks. -- Evertjan. The Netherlands. (Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | Osmo Saarikumpu <osmo@weppipakki.com> |
|---|---|
| Date | 2014-07-24 18:26 +0300 |
| Message-ID | <lqr8hk$ibg$1@dont-email.me> |
| In reply to | #25493 |
On 21.7.2014 8:15, Evertjan. wrote: > Thomas 'PointedEars' Lahn <PointedEars@web.de> wrote on 21 jul 2014 in > comp.lang.javascript: > >> for (var i = 0, plugins = navigator.plugins, len = plugins.length; >> i < len; ++i) > > Some semantic plugging-in: > > , var plugins = navigator.plugins, var len = plugins.length; > > methinks. I've never seen that suggested or used before. Are you sure? -- Best wishes, Osmo
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2014-07-24 17:48 +0200 |
| Message-ID | <XnsA374B517C957Deejj99@194.109.133.133> |
| In reply to | #25551 |
Osmo Saarikumpu <osmo@weppipakki.com> wrote on 24 jul 2014 in comp.lang.javascript: > On 21.7.2014 8:15, Evertjan. wrote: >> Thomas 'PointedEars' Lahn <PointedEars@web.de> wrote on 21 jul 2014 in >> comp.lang.javascript: >> >>> for (var i = 0, plugins = navigator.plugins, len = plugins.length; >>> i < len; ++i) >> >> Some semantic plugging-in: >> >> , var plugins = navigator.plugins, var len = plugins.length; >> >> methinks. > > I've never seen that suggested or used before. Are you sure? Can you give us any reason why 'i' should be varred, and 'plugins' and 'len' not? It could be [I did not think of it] that: var i = 0, plugins = navigator.plugins, len = plugins.length implicitly vars all 3, like it does in a simple statement. That could or could not be true, I see no way of testing that, because of the forhiving behavour of js implementations? -- Evertjan. The Netherlands. (Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2014-07-24 22:32 +0100 |
| Message-ID | <0.a05d769fd7d52c58503d.20140724223222BST.87vbqmbfyx.fsf@bsb.me.uk> |
| In reply to | #25553 |
"Evertjan." <exxjxw.hannivoort@inter.nl.net> writes:
<snip>
> It could be [I did not think of it] that:
>
> var i = 0, plugins = navigator.plugins, len = plugins.length
>
> implicitly vars all 3, like it does in a simple statement.
Yes, that's what the ECMA language specification says should happen.
> That could or could not be true, I see no way of testing that,
> because of the forhiving behavour of js implementations?
(function () {
for (var i = 0, j = 0; i < 1; i++);
})();
console.log(typeof i, typeof j);
You should see i and j undefined after the function execution. If you
remove the "var", you will see that both i and j are now shown as
"number". If the var applied to only one, you would see "undefined" and
"number".
--
Ben.
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2014-07-24 23:58 +0200 |
| Message-ID | <XnsA374F3EA19B3Deejj99@194.109.133.133> |
| In reply to | #25555 |
Ben Bacarisse <ben.usenet@bsb.me.uk> wrote on 24 jul 2014 in
comp.lang.javascript:
> "Evertjan." <exxjxw.hannivoort@inter.nl.net> writes:
> <snip>
>> It could be [I did not think of it] that:
>>
>> var i = 0, plugins = navigator.plugins, len = plugins.length
>>
>> implicitly vars all 3, like it does in a simple statement.
>
> Yes, that's what the ECMA language specification says should happen.
>
>> That could or could not be true, I see no way of testing that,
>> because of the forhiving behavour of js implementations?
>
> (function () {
> for (var i = 0, j = 0; i < 1; i++);
> })();
> console.log(typeof i, typeof j);
>
> You should see i and j undefined after the function execution. If you
> remove the "var", you will see that both i and j are now shown as
> "number". If the var applied to only one, you would see "undefined" and
> "number".
tnx.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | "Christoph M. Becker" <cmbecker69@arcor.de> |
|---|---|
| Date | 2014-07-24 18:40 +0200 |
| Message-ID | <lqrcu6$ov5$1@solani.org> |
| In reply to | #25551 |
Osmo Saarikumpu wrote: > On 21.7.2014 8:15, Evertjan. wrote: >> Thomas 'PointedEars' Lahn <PointedEars@web.de> wrote on 21 jul 2014 in >> comp.lang.javascript: >> >>> for (var i = 0, plugins = navigator.plugins, len = plugins.length; >>> i < len; ++i) >> >> Some semantic plugging-in: >> >> , var plugins = navigator.plugins, var len = plugins.length; >> >> methinks. > > I've never seen that suggested or used before. Are you sure? According to the ECMAScript specification, Edition 5.1[1], Evertjan.'s suggestion would be a syntax error. Besides, Thomas' example already declares all three variables. <http://www.ecma-international.org/ecma-262/5.1/#sec-12.6.3> -- Christoph M. Becker
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2014-07-25 12:31 +0200 |
| Message-ID | <22713596.r3qZ2B1LQr@PointedEars.de> |
| In reply to | #25554 |
Christoph M. Becker wrote: > Osmo Saarikumpu wrote: >> On 21.7.2014 8:15, Evertjan. wrote: >>> Thomas 'PointedEars' Lahn <PointedEars@web.de> wrote on 21 jul 2014 in >>> comp.lang.javascript: Attribution *line*, _not_ attribution novel. >>>> for (var i = 0, plugins = navigator.plugins, len = plugins.length; >>>> i < len; ++i) >>> >>> Some semantic plugging-in: >>> >>> , var plugins = navigator.plugins, var len = plugins.length; >>> >>> methinks. >> >> I've never seen that suggested or used before. Are you sure? > > According to the ECMAScript specification, Edition 5.1[1], Evertjan.'s > suggestion would be a syntax error. […] Yes, of course, but simply *testing* the code with any ECMAScript-based script engine would show that (all major browsers have a built-in script console, there are add-ons/bookmarklets and “javascript:” URIs for the others [1]). One should acquire a habit of testing code before posting it, or indicating that it is untested. Posting untested code can be excused as its complexity increases. [1] <http://PointedEars.de/faq#debugging> -- PointedEars FAQ: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/> Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix> Please do not Cc: me. / Bitte keine Kopien per E-Mail.
[toc] | [prev] | [next] | [standalone]
| From | John Harris <niam@jghnorth.org.uk.invalid> |
|---|---|
| Date | 2014-07-25 15:52 +0100 |
| Message-ID | <por4t99q14j1shs23rn5feakkqrp7b4p8s@4ax.com> |
| In reply to | #25563 |
On Fri, 25 Jul 2014 12:31:56 +0200, Thomas 'PointedEars' Lahn <PointedEars@web.de> wrote: <snip> >-- >PointedEars >FAQ: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/> >Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix> >Please do not Cc: me. / Bitte keine Kopien per E-Mail. Please do not post an essay in your "signature". John
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.javascript
csiph-web