javascript - 重定向

时间:2011-09-06 18:51:43

标签: javascript jquery sharepoint-2010

我可以让代码弹出警报但重定向不起作用。添加项目后,它应该重定向。

<script type="text/javascript" src="/_layouts/jquery/jquery-1.3.2.min.js"></script>
<script type="text/javascript">
fields = init_fields();
// Where to go when cancel is clicked
goToWhenCanceled = '/test/English/YouCanceled.aspx';

// Edit the redirect on the cancel-button's
$('.ms-ButtonHeightWidth[id$="GoBack"]').each(function(){
    $(this).click(function(){
            STSNavigate(goToWhenCanceled);
      })
});

// Edit the form-action attribute to add the source=yourCustomRedirectPage
function setOnSubmitRedir(redirURL){
var action = $("#aspnetForm").attr('action');
var end = action.indexOf('&');
    if(action.indexOf('&')<0){
        newAction = action + "?Source=" + redirURL;
    }else{
        newAction = action.substring(0,end) + "&Source=" + redirURL;
    }
$("#aspnetForm").attr('action',newAction);
alert(redirURL);
}

/*
// Use this for adding a "static" redirect when the user submits the form
$(document).ready(function(){
    var goToWhenSubmitted = '/test/English/ThankYou.aspx';
    setOnSubmitRedir(goToWhenSubmitted);
});
*/

// Use this function to add a dynamic URL for the OnSubmit-redirect. This function is automatically executed before save item.
function PreSaveAction(){
// Pass a dynamic redirect URL to the function by setting it here,
// for example based on certain selections made in the form fields like this:

    var dynamicRedirect = '/surveys/Pages/ThankYou.aspx';

    // Call the function and set the redirect URL in the form-action attribute
    setOnSubmitRedir(dynamicRedirect);
    alert(dynamicRedirect);
    // This function must return true for the save item to happen
    return true;
}

function init_fields(){
  var res = {};
  $("td.ms-formbody").each(function(){
      if($(this).html().indexOf('FieldInternalName="')<0) return;
      var start = $(this).html().indexOf('FieldInternalName="')+19;
      var stopp = $(this).html().indexOf('FieldType="')-7;
      var nm = $(this).html().substring(start,stopp);
      res[nm] = this.parentNode;
  });
  return res;
}
</script>

1 个答案:

答案 0 :(得分:4)

如果您在任何时候设置window.location.href = 'SomeUrl',那么它应该重定向。看看你的代码,我什么都看不到。

你想在什么时候重定向?