javascript in javascript
Hi, i have this external javascript. Basically i only want it to be loaded if the visitor has not seen it in the previous week.
My aim was to use a javascript cookie setter to see a cookie when the external javascript is first loaded and then check each time to see how long the visitor has not seen if for before it is loaded again.
Ok, how do i include an external javascript inside an internal javascript.
Otherwise, how could i do this using php? the pages are all php pages so that would be just fine. Is there some cookie setting code in php that could do the check and then the results send the javascript. I am new to php so any actual cookie code that would do this would be greatly appreciated.
Thanks.
ascifi.com The Science Fiction Community
Mark Hensler posted this at 05:52 — 13th September 2000.
He has: 4,048 posts
Joined: Aug 2000
Hello, and welcome!
how does you external javascript look? is it encassed in a function? if so you could use the javascript cookie, and execute the functin if no cookie exists. That is about as much of that javascript stuff as I know.
PHP- I love PHP
There is an easy cookie thingy!
syntax:
setcookie("CookieName", "CookieValue", "TimeUntillExpire");
Example:
if (isset($Visited) && $Visited == "yes") {
//do nothing
}
else{
print ("
//your javascript link can go here
');
}
setcookie(Visited, "yes", time()+(60*60*24*365));
If the cookie exists AND it's value is "yes" THEN do nothing.
If the cookie DOES NOT exist OR it's value is something other that "yes" THEN print the javascript.
This cookie will expire one year after the users last visit (because it re-sets the expiration time evey visit).
good luck,
Mark Hensler
If there is no answer on Google, then there is no question.
ascifi posted this at 10:26 — 13th September 2000.
They have: 7 posts
Joined: Sep 2000
This is how the javascript was called:
<script LANGUAGE="JavaScript" src="http://www.popuptraffic.com/assign.php?l=ascifi"></script>
looking at it again, it is not reall javascript i guess. bit weird really.
Anyway, the page it is going to go on is php so that is ok.
so how would i convert that into "javascript link can go here" ?
ascifi.com The Science Fiction Community
Mark Hensler posted this at 05:44 — 14th September 2000.
He has: 4,048 posts
Joined: Aug 2000
and I'm a bit corn-fuzzed about a javascript link pointing to a php. never seen that before. I wouldn't think that'a work.
what is the format of the page calling the javascript? is it PHP too? or just .html?
I'm going to assume that the page calling it is PHP...
Where ever you currently have the <script> tag, cut it out. and paste this:
<?
if (!isset($Visited) || $Visited != "yes") {
?>
<script LANGUAGE="JavaScript" src="http://www.popuptraffic.com/assign.php?l=ascifi"></script>
<?
}
setcookie(Visited, "yes", time()+(60*60*24*365));
?>
this will print your <script> tag only if the cookie is not set, or the cookie's value is not "yes". [This means that later, you could change the keyword to get everyone to see one more time. To do this you would just change both "yes" to "whatever"]
Hope that helps.
Mark Hensler
If there is no answer on Google, then there is no question.
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.