您好,欢迎访问一九零五行业门户网

js获取html参数及向swf传递参数应用介绍_javascript技巧

我们知道html页面是在客户端执行的,这样要获取参数必须使用客户端脚本(如javascript),在这点上不同于服务器端脚本获取参数方式。
下面的这段js代码获取html网页形如test.html?foo=mytest&program=flash ?后所有参数。
复制代码 代码如下:
一、下面的这段js代码则可以更加细化获取html网页某一参数
复制代码 代码如下:
二、在html网页中向swf传递参数
方法一:在网页中使用js,setvariable设置flashobject中的变量,代码如:
复制代码 代码如下:
// htmltoswf为网页中的flashobject id
htmltoswf.setvariable(_root.info_str,happy newyear);
方法二:路径参数,如test.swf?foo=happy2005
方法三:使用flashvars,以下主要介绍flashvars的用法。使用flashvars后嵌入html的flashobject代码如下:
复制代码 代码如下:
字串5
通过上面的代码,在swf(flashvars.swf)中就可以直接获取foo、program、language变量数据。flashvars.fla获取flashvars参数的代码如下:
复制代码 代码如下:
// 创建三个文本字段
_root.createtextfield(foo_txt,1,0,0,16,16);
_root.createtextfield(program_txt,2,0,32,16,16);
_root.createtextfield(language_txt,3,0,64,16,16);
foo_txt.autosize = true;
字串8
foo_txt.border = true;
program_txt.autosize = true;
program_txt.border = true;
language_txt.autosize = true;
language_txt.border = true;
// 获取flashvars变量
foo_txt.text = html中的foo参数: foo;
program_txt.text = html中的program参数: program;
language_txt.text = html中的language参数: language;
三、两者的有效结合
在html网页中使用js获取参数,然后将获取的参数作为flashvars写入flashobject传递给swf。代码如下:
复制代码 代码如下:
其它类似信息

推荐信息