Partilhar via


SP.Utilities.HttpUtility.appendSourceAndNavigateTo(url) Method

Applies to: SharePoint Foundation 2010

Appends the source URL to the specified URL and then navigates to the specified URL.

SP.Utilities.HttpUtility.appendSourceAndNavigateTo(url);

Parameters

url

Type: string

The URL need to be appended.

Remarks

The total length of the appended URL must be less than 1950 characters.

Applies To

SP.Utilities.HttpUtility Class

Example

The following example creates an Input button on an application page that encodes the URL of the All Tasks View of the current site, and then navigates to the msn.com site.

<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
<script type="text/ecmascript" language="ecmascript">

    var web;
    var view;
    var newUrl;
    function runCode() {
        var clientContext = new SP.ClientContext.get_current();
        if (clientContext != undefined && clientContext != null) {
            web = clientContext.get_web();
            var listCollection = this.web.get_lists();
            var list = listCollection.getByTitle("Tasks");
            this.view = list.get_views().getByTitle("All Tasks");
            clientContext.load(this.view);
            clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
        }
    }

    function onQuerySucceeded() {

        var viewServ = this.view.get_serverRelativeUrl();
        var encodedUrl = SP.Utilities.HttpUtility.ecmaScriptStringLiteralEncode(viewServ);
        newUrl = 'https://www.msn.com';
        
        alert('Encoded All Tasks View URL: ' + encodedUrl);
        alert('Navigating to msn.com...');
        SP.Utilities.HttpUtility.appendSourceAndNavigateTo(this.newUrl);
    }

    function onQueryFailed(sender, args) {
        alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
    }

</script>

    <input id="Button1" type="button" value="Run Code" onclick="runCode()" />

</asp:Content>

See Also

Reference

SP.Utilities.HttpUtility Methods

SP.Utilities Namespace