2011-09-06 134 views
0

我可以讓代碼彈出警告但重定向不起作用。添加一個項目後,它應該重定向。javascript - 重定向

<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> 

回答

4

如果你在任何時候設置了window.location.href = 'SomeUrl',它應該重定向到那麼。看着你的代碼,我沒有看到任何地方。

您在什麼時候嘗試重定向?

+0

我以爲這條線正在做重定向。 $( 「#aspnetForm」)ATTR( '行動',newAction)。 –

+0

@瑪麗河,沒有window.location是做它的標準方式。 – riwalk

+0

正確。使用您的jQuery版本,只需更改表單提交時發佈的表單操作即可。實際上沒有行動正在執行。即使在SharePoint 2010中也有 – Tejs