Introduction to js app for obtaining html parameters and passing parameters to swf

Source: Internet
Author: User

We know that the HTML page is executed on the client. To obtain parameters, you must use a client script (such as JavaScript), which is different from the method used by the server script to obtain parameters.

The following js Code retrieves an HTML webpage, such as "test.html? Foo = mytest & program = flash ""? All parameters.Copy codeThe Code is as follows: <script language = javascript>
<! --
Var hrefstr, pos, parastr;
Hrefstr = window. location. href;
Pos = hrefstr. indexOf ("? ");
Parastr = hrefstr. substring (pos 1 );
If (pos> 0 ){
Document. write ("All parameters:" parastr );
} Else {
Document. write ("No parameter ");
}
// -->
</Script>

1. The following JavaScript code can be used to obtain a parameter of an HTML webpage in more detail. Copy codeThe Code is as follows: <script language = javascript>
<! --
Function getparastr (strname ){
Var hrefstr, pos, parastr, para, tempstr;
Hrefstr = window. location. href;
Pos = hrefstr. indexOf ("? ") String 9
Parastr = hrefstr. substring (pos 1 );
Para = parastr. split ("&");
Tempstr = "";
For (I = 0; I <para. length; I)
{
Tempstr = para [I];
Pos = tempstr. indexOf ("= ");
If (tempstr. substring (0, pos) = strname ){
Return tempstr. substring (pos 1 );
}
}
Return null;
}
// Obtain the program parameter
Var programstr = getparastr ("program ");
Document. write (programstr );
// -->
</Script>

2. Passing parameters to swf on an HTML webpage
Method 1: Use js and SetVariable on the webpage to set variables in flashobject. The Code is as follows:Copy codeThe Code is as follows: // "HtmlToSwf" indicates the flashobject ID in the webpage.
HtmlToSwf. SetVariable ("_ root.info _ str", "Happy Newyear ");

Method 2: Upload requests, such as test.swf? Foo = happy2005
Method 3: Use FlashVars. The following describes how to use FlashVars. The flashobject code embedded in HTML after FlashVars is as follows:Copy codeThe Code is as follows: <object classid = "clsid: d27cdb6e-ae6d-11cf-96b8-444553540000" codebase = "http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width = "550" height = "400" id = "FlashVars" align = "middle"> string 5
<Param name = "allowScriptAccess" value = "sameDomain"/>
<Param name = "movie" value = "FlashVars.swf"/>
<Param name = "FlashVars" value = "foo = happy2005 & program = flash & language = Simplified Chinese-China"/>
<Param name = "quality" value = "high"/>
<Param name = "bgcolor" value = "# ffffff"/>
<Embed src = "FlashVars.swf" quality = "high" bgcolor = "# ffffff" width = "550" height = "400" name = "FlashVars" align = "middle" allowScriptAccess = "never" allowNetworking = "internal" autostart = "0" FlashVars = "foo = happy2005 & program = flash & language = Simplified Chinese-China" type = "application/x-shockwave- flash "pluginspage =" http://www.macromedia.com/go/getflashplayer "/>

Through the authorization code, you can directly obtain the foo, program, and language variable data in swf(flashvars.swf. The code for obtaining the FlashVars parameter from FlashVars. fla is as follows:Copy codeThe Code is as follows: // create three text fields
_ Root. createTextField ("foo_txt", 16 );
_ Root. createTextField ("program_txt", 2, 0, 32, 16, 16 );
_ Root. createTextField ("cmdage_txt", 64, 16, 16 );
Foo_txt.autoSize = true;
String 8
Foo_txt.border = true;
Program_txt.autoSize = true;
Program_txt.border = true;
Required age_txt.autosize = true;
Required age_txt.border = true;
// Obtain the FlashVars variable
Foo_txt.text = "foo parameter in HTML:" foo;
Program_txt.text = "parameter program in HTML:" program;
Language_txt.text = "language parameter in HTML:" language;

Iii. Effective combination of the two
Use js in the HTML webpage to get parameters, and then write the obtained parameters as FlashVars to flashobject and pass it to swf. The Code is as follows:Copy codeThe Code is as follows: <script language = javascript>
<! --
Function writeflashobject (parastr ){
Document. write ("<object classid = \" clsid: d27cdb6e-ae6d-11cf-96b8-444553540000 \ "codebase = \" fill "width = \" 550 \ "height = \" 400 \ "id = \" FlashVars \ "align = \" middle \ "\> \ n ");
Document. write ("<param name = \" allowScriptAccess \ "value = \" sameDomain \ "/\> \ n ");
Document. write ("<param name = \" movie \ "value = \" FlashVars.swf \ "/\> \ n"); string 2
Document. write ("<param name = \" FlashVars \ "value = \" "parastr" \ "/\> \ n ");
Document. write ("<param name = \" quality \ "value = \" high \ "/\> \ n ");
Document. write ("<param name = \" bgcolor \ "value = \" # ffffff \ "/\> \ n ");
Document. write ("<embed src = \" FlashVars.swf \ "quality = \" high \ "bgcolor = \" # ffffff \ "width = \" 550 \ "height = \" 400 \ "name = \" FlashVars \ "align = \" middle \ "allowScriptAccess = \" sameDomain \ "FlashVars = \" "parastr" \ "type = \" application/x-shockwave -flash \ "pluginspage = \" http://www.macromedia.com/go/getflashplayer\ "/\> ");
Document. write ("</object \> ");
}
Function getparastr (){
Var hrefstr, pos, parastr, para, tempstr1;
Hrefstr = window. location. href;
Pos = hrefstr. indexOf ("? ")
Parastr = hrefstr. substring (pos 1 );
Return parastr;
}
Var parastr = getparastr ();
Writeflashobject (parastr );
// -->
</Script>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.