Forum Moderators: open

Message Too Old, No Replies

Help w/ displaying JS results

         

tjhorne

12:59 pm on Jun 24, 2005 (gmt 0)

10+ Year Member



My script is below, I am just not sure how to take the results out and display them in my webpage, any help would be greatly appreciated.

<script>
var acrobat=new Object();

acrobat.installed=false;
acrobat.version='0.0';

if (navigator.plugins && navigator.plugins.length)
{
for (x=0; x {
if (navigator.plugins[x].description.indexOf('Adobe Acrobat')!= -1)
{
acrobat.version=parseFloat(navigator.plugins[x].description.split('Version ')[1]);

if (acrobat.version.toString().length == 1) acrobat.version+='.0';

acrobat.installed=true;
break;
}
}
}
else if (window.ActiveXObject)
{
for (x=2; x<10; x++)
{
try
{
oAcro=eval("new ActiveXObject('PDF.PdfCtrl."+x+"');");
if (oAcro)
{
acrobat.installed=true;
acrobat.version=x+'.0';
}
}
catch(e) {}
}

try
{
oAcro4=new ActiveXObject('PDF.PdfCtrl.1');
if (oAcro4)
{
acrobat.installed=true;
acrobat.version='4.0';
}
}
catch(e) {}

try
{
oAcro7=new ActiveXObject('AcroPDF.PDF.1');
if (oAcro7)
{
acrobat.installed=true;
acrobat.version='7.0';
}
}
catch(e) {}

}
</script>

rocknbil

5:23 pm on Jun 24, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Store the relevant data in a variable. You then later do a document.write to display it. Relevant additions bolded.

I've also bolded a section of the "for" loop you left out.

<html><head><title>Detect Acrobat</title>

<script type="text/javascript">
//Script type required to validate
var displayString;

var acrobat=new Object();

acrobat.installed=false;
acrobat.version='0.0';

if (navigator.plugins && navigator.plugins.length) {
for (x=0; x<navigator.plugins.length;x++) {
if (navigator.plugins[x].description.indexOf('Adobe Acrobat')!= -1)
{
acrobat.version=parseFloat(navigator.plugins[x].description.split('Version ')[1]);

if (acrobat.version.toString().length == 1) acrobat.version+='.0';

acrobat.installed=true;
displayString = 'Acrobat Version: '+acrobat.version;
break;
}
}
}

else if (window.ActiveXObject)
{
for (x=2; x<10; x++)
{
try
{
oAcro=eval("new ActiveXObject('PDF.PdfCtrl."+x+"');");
if (oAcro)
{
acrobat.installed=true;
acrobat.version=x+'.0';
displayString = 'Acrobat Version: '+acrobat.version;
}
}
catch(e) {}
}

try
{
oAcro4=new ActiveXObject('PDF.PdfCtrl.1');
if (oAcro4)
{
acrobat.installed=true;
acrobat.version='4.0';
displayString = 'Acrobat Version: '+acrobat.version;
}
}
catch(e) {}

try
{
oAcro7=new ActiveXObject('AcroPDF.PDF.1');
if (oAcro7)
{
acrobat.installed=true;
acrobat.version='7.0';
displayString = 'Acrobat Version: '+acrobat.version;
}
}
catch(e) {}

}

// Always do SOMETHING in case it goes wrong
if (! displayString) { displayString = 'Acrobat Installed: Information Not Available'; }

// this alert is just to test if document.write doesn't work
//alert(displayString);

</script>

</head>
<body>

Then, anwhere on the page you want to put this,<br>

<script type="text/javascript">
// Always do an if in case something goes wrong in populating displayString. Errors are ugly.
if (displayString) {
document.write(displayString);
}
</script>

</body>
</html>

tjhorne

7:51 pm on Jun 24, 2005 (gmt 0)

10+ Year Member



Your the man! I've been beating my head in all day on this one, thanks again for you're help!