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.

2

3 Answers 3

3

The most efficient way will be, use Cookies

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.