3

I am currently working on the project that have 2 php files category.php and product.php.

In category.php file i put a link shown below.

<a href="product.php?cat=getcate" class="option">click here</a>

I have the following js function called on the body onload in the product.php page.

<body onload="font_select(1760,'No',239)">

When users click on the link then they will be redirect to product.php file where the body onload function is called.this function is working fine.

My question is i need to call this function only once when the user enter in product.php page.currently this function is called on page reload also.

How would i call this function only once ? Thanx In Advance.

Jimmy
  • 373
  • 1
  • 16

3 Answers3

3

The most efficient way will be, use Cookies

Ravi
  • 2,078
  • 13
  • 23
0

(It's a little kludgy, but you could check document.referrer in font_select) well that's wrong, turns out at least in firefox the referrer does not change apparently when the page is refreshed.

You may want to have a look at this question, where they handle detecting refresh using a cookie, however you should know that is really just a check if the page has been accessed before so it won't work unless you also clear that cookie on detecting a click on the link from your category.php page.

Community
  • 1
  • 1
Chris O'Kelly
  • 1,863
  • 2
  • 18
  • 35
0

Go for javascript cookies

well to track whether the function is called or not, you could use javascript cookie. Like say you set a cookie with any name, say functioncalled with value 0 initially, when user goes to product page, check this cookie. If value is 0, then call a function then set the value of cookie to 1, next time when page is reloaded the function will not be called.

WatsMyName
  • 4,240
  • 5
  • 42
  • 73