Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

global variables in javascript for adobe

348 views
Skip to first unread message

Andrea Kubacki

unread,
Jan 22, 2003, 7:05:55 AM1/22/03
to
Hi,

I have the following problem. I have a script on PageOpen, and it should only passed through once. I have found the following method, to solve this problem, when I first open the form:
var PageOpen = 0
if(PageOpen < 1)
{
PageOpen++
my script...
}
But this works only for the first time. When I save the document, and invoke the document later, the script run is passing through, for another time. How can I solve this problem. I thought on save the content of the variable, but I don`t no, how to manage this.

klgc

unread,
Jan 22, 2003, 7:45:34 AM1/22/03
to
Whether you have a numeric or boolean indicator, to save such accross viewer sessions you need the setPersistent method of the Global Object. Page 195 of the Acrobat JavaScript Object Specification (Help menu) and Module 3 page 6 of the Acrobat JavaScript Course:
<http://partners.adobe.com/asn/developer/training/acrobat/javascript/main.html>

Keep in mind that this saves the variable in your folder level JS glob.js file and there is a 32K limit for all such variables. Also keep in mind that this is a "Local" state - someone opening the PDF elsewhere will not have the same folder level js. Anyway, that is how I understand it - I only use such in a "local" setting.

Hope this helps with your Global question.
Lee C

Tobias Hugener

unread,
Jan 22, 2003, 8:04:05 AM1/22/03
to
In addition to Lee's comment:

if (typeof global.pageOpen == "undefined") global.pageOpen = 0;
if (global.pageOpen == 0) {
your script...
}
global.pageOpen++;
global.setPersistent("pageOpen", true);

Tobias

George Johnson

unread,
Jan 22, 2003, 1:31:19 PM1/22/03
to


var PageOpen = 0
if(PageOpen < 1)
{
PageOpen++
my script...
}

To make it work like you want, it should be:



// Will initialize to 0
var PageOpen;

if(PageOpen < 1)
{
PageOpen++
my script...
}

When this code is first hit, the variable "PageOpen" will be given a value of 0, or false. Your code then sets it to 1, or true. The next time the code is hit, PageOpen will be equal to 1. Since your code was resetting PageOpen to 0 each time, it doesn't have the desired effect.

I do this a bit differently, by explicitly setting the value in a document-level routine which runs when the PDF is opened. Something like:



var PageOpen = false;

The code would then be:



if(PageOpen < 1)
{
PageOpen = true;
my script...
}

George

0 new messages