Variable
- Started
- Last post
- 20 Responses
- stewart
i have this useful actionscript for adding a variable behind a loaded filename:
--------
_root.MC1.onRelease = function () {
rn = Math.round(Math.random()*10);
_root.MC2.loadMovie("file.swf?re...
}
-------i'm looking for something similar but in a html website, so that a linked html document gets a random variable behind it's name...
- sparker0
php or perl is what you seek. these scripting languages would allow such a function.
- heavyt0
although i dont fully understand the request, i think that it is possible in javascript too.
can you please clarify the before and after of this?
TR1
- stewart0
well heavyt,
i use the posted actionscript for loading an external .swf file into flash, but to avoid cachingproblems i add a variable behind the filename that is stored in the browsers' cache. everytime you click the link, another variable is put behind the name so each time it is unique.
at least unfit told me that, and i believe him.
but now i wonder, is there something similar for use in html/javascript?
i hope this is more clear than the first post. damn english.
- sparker0
javascript would work, too.
html is just markup.
- stewart0
okay. so you suggest http://www.google.com ?
- stewart0
doh!
- rabattski0
so you want to read that url specified variable in flash? if so a simple html href, e.g. page.html?variable=here would work.
- dc_again0
i'm not 100% sure what you require, but using a flat html/javascript combination is stateless. in other words, there would be no memory of the previous variable the next time you request the page, so you couldn't check if it had been requested before.
to use javascript, you would have to write a cookie. then create random number, and write that within your cookie. next time the page is requested, check to see if your random number is in the cookie. if it isn't, you're ok so create another random number and overwrite your cookie. simple.
besides javascript, as said before, a server side language would be needed - perl, php, cold fusion, etc.
hope this helps.
- rabattski0
well if you're going to use e.g. php you might as well skip the whole cookies thing and work with sessions. right?
- dc_again0
of course, you could do as rabattski said, and use javascript to write the variable to the url, then it isn't stateless. however, this is very unreliable and unsafe - what happens if the user removes the variable in the address, what happens if the user adds his/her own variable number in the address, what happens if your script is looking for a number and the user adds text to the address, etc, etc.
by the time you cover all the bases, you'd have been better off using something else.
- dc_again0
rabattski - exactly. and using sessions in php or asp is like falling off a log.
- rabattski0
it's really unclear what stewart wants. you can do it without javascript actually. just, you know, specifying a var thru a basic html href tag and reading that in flash should work without any problems. then again, i have no clue whatsoever what the exact problem is. :)
- stewart0
oh shit, is my english so Wendell-is?!
attempt 3:
• when i click on a hyperlink in a html website a new html file loads.
right?• that loaded html file is stored in the browser cache, together with that file name, say file.html.
okay?• what i want is that everytime that file.html is loaded by clicking the hyperlink, a variable number is added behind the document name, say
href=file.html+date+time
so the cached name is always unique.• so, when i click the hyperlink to load file.html, this document isn't loaded from the cache, because the filename in the cache is different, because the added variable.
holy shit, i think when i type more and more, my story gets blurrier and blurrier.
i got this first posted actionscript from Unfit to do the same in flash with .swf files, everytimie a swf file is loaded a random number is added to the cached .swf file, and that works great!
- dc_again0
ok, ok. so are we saying that all you want to ensure is that your html page is *never* loaded from the cache, but always from the server? if so, this is very easy. there are two meta tags that you need to place straight after the title tag. one is something like meta=no-cache, the other is like meta=expires, where you set your page to expire in 1970 so that the browser always gets a new version. just do a google for meta tags and look for expires and no-cache.
appending something to the url using javascript won't get the browser to get the lates version of the page, as it has no server scope. its just an identifier.
hope this helps this time!
- stewart0
thanks dc, BUT:
i noticed that the "no-cache" tag doesn't work for all browsers, and also embedded swf files are cached even when i use the "no-cache" tag.
the "expires" tag is even worse, because pages with this tag are not ranked in google, because they're expired...
...so i thaught, is there a way to put a variable behind the loaded filenames (loaded .html files, embedded .swf files etc etc)...
- stewart0
Wendell where are you?
Please explain them what i try to say!
- rabattski0
like dc said. adding a random variable to an url. e.g. test.html?random=1 doesn't make it a new page. test.html is still retreived from the cache.
anyways, maybe you should it by using php. read this:
- stewart0
okay thanks rabattski
i have a WinNT webserver so no PHP here
but ok, i'll shutup now
- rabattski0
no php? that sucks. well other than php and dc suggestions (meta etc.) i have no clue whatsoever how you could solve your problem.
- dc_again0
WinNT? you got asp then stewart? works as well as php. not as sexy, but works the same.
(still not sure what you want though! sorry!..... merry christmas!)