简体   繁体   English

如何将FlashVars参数更改为URL查询字符串?

[英]How can I change FlashVars parameters into a URL query string?

I understand that when retrieving an SWF file and passing parameters to that file while doing so, there are two options to do this: using the FlashVars or the query string technique. 我了解到,在检索SWF文件并在执行此操作时将参数传递给该文件时,有两种方法可以执行此操作:使用FlashVars或查询字符串技术。

Say I wish to obtain the swf file directly via HTTP so that I can download the file, and I know from the source code that the file, when embedded, is passed the the following parameters via FlashVars with the following Javascript code: 假设我希望直接通过HTTP获取swf文件,以便我可以下载该文件,并且从源代码中得知,该文件在嵌入时会通过FlashVars使用以下Javascript代码传递以下参数:

// used to validate hour parameter
            var numberOfSegments = 1;

            var flashvars1 = {};
            flashvars1.url = "http://cm.dce.harvard.edu/2014/02/23515/L12/23515-20140502-L12-H264HighBandwidthTalkingHead-16x9.xml";
            flashvars1.videoWidth = "374";
            flashvars1.videoHeight = "210";
            flashvars1.resizable = true;
flashvars1.hour = 1;
flashvars1.autoPlay = true;
flashvars1.largeTH = false;
flashvars1.cdn = false;


            //<!-- 
            // This will create or overwrite optional HOUR parameter
            // Tests if URL had query argument: "?part=3" 
            // Checking for part in range prevents flash #1006 error 
            if (location.search != ""){
                var queryStr = location.search.split('?');
                if(queryStr.length > 1){
                    queryStr = queryStr[1];
                    var queryArray = queryStr.split("&");
                    for ( var i = 0; i < queryArray.length; i++){
                        var pair = queryArray[i].split("=");
                        if ((pair[0] == "part") && (pair.length > 1) && !isNaN(pair[1])){
                            if((numberOfSegments != null) && (0 < pair[1]) && (pair[1] <= numberOfSegments) ){
                                flashvars1.hour = pair[1];
                            } // make sure hour value is in range
                        } // end if HOUR is part of query 
                    }  // end query pair array loop
               }  // end if query has content
            } // end if query exists
            // -->
            var params1 = {};
            params1.quality = "high";
            params1.bgcolor = "#ffffff";
            params1.allowscriptaccess = "sameDomain";
            params1.allowfullscreen = "true";
            params1.wmode = "transparent";

            var attributes1 = {};
            attributes1.id = "flashContent1";
            attributes1.name = "flashContent1";
            attributes1.align = "middle";

            swfobject.embedSWF(
                "/flash/FlashViewer.swf", "flashContent1", 
                "100%", "100%", 
                swfVersionStr, xiSwfUrlStr, 
                flashvars1, params1, attributes1);

How then do I translate FlashVars into a query string I can append at the end of the swf URL? 然后,如何将FlashVars转换为可以在swf URL末尾附加的查询字符串?

This should give you the a query string with all the values from the flashvars1 JSON object: 这应该为您提供一个查询字符串,其中包含flashvars1 JSON对象中的所有值:

var querystring = "?";
for (var key in flashvars1) {
  if (flashvars1.hasOwnProperty(key)) {
    querystring += key + "=" + flashvars[key] + "&";
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在事件处理程序onclick之后,如何正确更改URL的查询字符串中的参数? - How can I change correctly the parameters in the query string for a URL after the event handler onclick? 如何加密和解密查询我在 URL 中的查询参数? - How can I encrypt and decrypt query my query parameters in a URL? “如何在 javascript 中获取 google apps 脚本 web 应用沙箱的 url 查询字符串参数? - "How can I get the url query string parameters of a google apps script web app sandbox in javascript? 如何使用Chrome扩展程序的ContentScript更改Flashvar? - How do I change the flashvars using the ContentScript of a Chrome Extension? 如何使用jQuery替换部分flashvars属性 - How can I replace part of an embed flashvars attribute using jQuery 如何创建链接到带有查询参数的按钮的 URL? - How can I create a URL that links to a button press with query parameters? 如何更改查询字符串(实时)? - How can i change the query string (live)? 如何从字符串中获取带有表单参数的 url? - how can i get a url with form parameters from a string? 如何获取URI参数-使用JavaScript查询字符串? - How can I get URI parameters - query string with JavaScript? 如何在URL中获取第一个查询字符串的值 - How can i get the value of first query string in a URL
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM