为object参数赋值

时间:2014-12-22 20:11:44

标签: javascript sharepoint

我在共享点中嵌入了代码。我需要将javascript值传递给参数。我怎么能在这里做到这一点?请参阅第3个参数PUT_FUNCTION_VALUE_HERE以供参考。

<script type="text/javascript">
function getUrlParameters(parameter, staticURL, decode){
   /*
    Function: getUrlParameters
    Description: Get the value of URL parameters either from 
                 current URL or static URL
    Author: Tirumal
    URL: www.code-tricks.com
   */
   var currLocation = (staticURL.length)? staticURL : window.location.search,
       parArr = currLocation.split("?")[1].split("&"),
       returnBool = true;

   for(var i = 0; i < parArr.length; i++){
        parr = parArr[i].split("=");
        if(parr[0] == parameter){
            return (decode) ? decodeURIComponent(parr[1]) : parr[1];
            returnBool = true;
        }else{
            returnBool = false;            
        }
   }

   if(!returnBool) return false;  
}
function getUrlParametersWrite(parameter, staticURL, decode){
                var vlaue = getUrlParameters(parameter, staticURL, decode);
                alert(value);
                document.write(value);
                document.close();
}

</script>


<script type='text/javascript' src='http://myview.fake.org/javascripts/api/viz_v1.js'></script>
<div class='tableauPlaceholder' style='width: 984px; height: 634px;'>
    <object class='tableauViz' width='984' height='634' style='display:none;'>
        <param name='host_url' value='http://myview.fake.org' /> 
        <param name='site_root' value='' />
        <param name='name' value='MemberParticipationReporting&#47;MemberParticipationDashboard&Fice=PUT_FUNCTION_VALUE_HERE' />
        <param name='tabs' value='yes' />
        <param name='toolbar' value='yes' />
    </object>
</div>

1 个答案:

答案 0 :(得分:0)

使用jQuery,这将非常简单。

function getUrlParametersWrite(parameter, staticURL, decode){
  var value = getUrlParameters(parameter, staticURL, decode);
  var att = $("param[name='name']").attr("value");
  att = att.replace("PUT_FUNCTION_VALUE_HERE",value);
  $("param[name='host_url']").attr("value",att);
}

我假设您正在尝试设置host_url参数。

使用直接JavaScript,这应该有效:

function getUrlParametersWrite(parameter, staticURL, decode){
  var value = getUrlParameters(parameter, staticURL, decode);
  var params = document.getElementsByName("name");
  var att = params[0].getAttribute("value");
  att = att.replace("PUT_FUNCTION_VALUE_HERE",value);
  params[0].setAttribute("value",att);
}