Forum Moderators: open
<script type="text/javascript">
window.$_GET=(function(){
var get_array=new Object();
if(!location.search)return get_array;
var p=location.search.replace(/\+/g,"%20").substr(1).split("&"),l=p.length;
for(var i=0,t;i<l;i++){
t=p[i].split("=");
if(!t[0])t[0]="";
if(!t[1])t[1]="";
t[0]=decodeURIComponent(t[0]);
t[1]=decodeURIComponent(t[1]);
get_array[t[0]]=t[1];
}
return get_array;
})();
</script>
<script type="text/javascript">
alert($_GET['game']);
</script>
I could also do
embed src= http://www..... "game name" .swf
But I would like to learn the other way,
Yes, I am aware I am using a free domain, a .com with the word "game" in it sets off the schools firewall, that and i don't want to pay for one (I'm cheap)
Thanks!
[edited by: Fotiman at 5:31 pm (utc) on Dec. 22, 2009]
[edit reason] Examplified URLs [/edit]
If you are trying to embed a script from another site, you can dynamically add a new <script> element to the <head> element. Something along these lines should work:
var newScript = document.createElement('script');
newScript.type = "text/javascript";
newScript.src = 'http://www.example.com/embed/' + $_GET['game'] + '.js';
document.documentElement.getElementsByTagName("HEAD")[0].appendChild(newScript);
<script type="text/javascript">
function get_search_string()
{
var fullurl=window.location.search
var param=(fullurl.slice(1))
var pairs = param.split("&")
var targetvar = "game"
for(var i = 0; i < pairs.length; i++)
{
var pos = pairs[i].indexOf('=')
if (pos == -1) continue
var argname = pairs[i].substring(0,pos)
var value = pairs[i].substring(pos+1)
if (argname == targetvar)
{
var searchstring = value
{break}
}
}
return searchstring
}
</script>
<script type="text/javascript">
var domain = "http://example.com/embed/"
var file = ".js"
var embed = domain + value + file
</script>
<script type="text/javascript">
document.write('<sc'+'ript');
document.write(' type="text/javascript"');
document.write(' language="JavaScript"');
document.write(''+embed+'">');
document.write('</sc'+'ript>');
</script>
<BR><BR><BR><BR><BR><BR><BR><BR><BR><BR>
<p>TEST</p>
</body>
TEST does appear
You can try it at
SNIP
Thanks in advance, any help counts!
[edited by: Fotiman at 5:38 pm (utc) on Dec. 22, 2009]
[edit reason] No URLs please. See TOS [webmasterworld.com] [/edit]