View Full Version : Very Easy Request
eckels2
12-22-2002, 04:49 PM
I have a javascript that loads when the page loads. I would like the user to be able to turn it on or off. That is, i want the user to have the option of the script loading when the page loads, or not loading.
How i'd like to do it, is to either use a cookie, or a field in the database to store a value, that says whether or not the script should run when the page loads.
I imagine the cookie would be easier.
Can anyone give me a general idea of what to do? or help me out with some php that does something like that?
Logician
12-22-2002, 07:40 PM
How about this:
Create a new userprofile field in Admin CP hidden in profile but editable by the users, note its id
Tell your users to enter "YES" there if they want to load the script.
Then edit global.php, find:
// parse PHP include ##################
Before that add:
if (strtolower($bbuserinfo[fieldX])=='yes') {$yourjavacode='ENTER CODE HERE';}
(Replace X with your field id)
Then you can use "$yourjavacode" variable in your relavant template like header..
eckels2
12-27-2002, 01:59 AM
it doesn't seem to parse $yourjavacode. it just leaves "$code" in the page, without it being replaced by the actual code.
what it thought of, is it might be my code that i'm trying to replace it with... the necessary java code is onLoad="snow()"...
so it looked like if (strtolower($bbuserinfo[field6])=='yes') {$yourjavacode='onLoad="snow()"';}
Should i do it differently? is that the problem?
filburt1
12-27-2002, 02:39 AM
No need to hack; I mean you just referenced PHPinclude...install this (http://www.vbulletintemplates.com/mods/showthread.php?s=&threadid=2361) first (I can never remember the eval template code) and then add this:
if (strtolower($bbuserinfo['fieldn']) == "yes")
{
eval(makeevaltemplatecode("jscodeinsert", "templatenamethathasonlythejavascriptinit"));
}
Then insert $jscodeinsert wherever you want the code to go.
Logician
12-27-2002, 08:55 AM
Originally posted by eckels2
it doesn't seem to parse $yourjavacode. it just leaves "$code" in the page, without it being replaced by the actual code.
what it thought of, is it might be my code that i'm trying to replace it with... the necessary java code is onLoad="snow()"...
so it looked like if (strtolower($bbuserinfo[field6])=='yes') {$yourjavacode='onLoad="snow()"';}
Should i do it differently? is that the problem?
You should be inserting the "$yourjavacode" variable into the wrong template. I tested it by inserting it into "headinclude" template and it works as it should be..
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.