Skip to main content
Tweeted twitter.com/StackSharePoint/status/873217538288648192
deleted 28 characters in body
Source Link

I am working with SharePoint Online.

I have a requirement where I have to add Quick Launch Navigation Item and call JavaScript function on click of the item. I am using code shown here.

Following is my code:

var oQuickLaunchColl;
function addNavigation() {
    var testt = "javascript:callNavigationAction()";
    var clientContext = new SP.ClientContext();
    var oWeb = clientContext.get_web();
    oQuickLaunchColl = oWeb.get_navigation().get_quickLaunch();
    var oNavigation = new SP.NavigationNodeCreationInformation();
    oNavigation.set_title("Start new Chat");
    oNavigation.set_url(testt'javascript:callNavigationAction()');
    oQuickLaunchColl.add(oNavigation);
    clientContext.load(oQuickLaunchColl);
    clientContext.executeQueryAsync(QuerySuccess1, QueryFailure1);
}
function QuerySuccess1() {
    //Get the item count of navigation nodes and loop through it  
    var itemCount = oQuickLaunchColl.get_count();
    console.log("The navigation node details are:");
    for (var i = 0; i < itemCount; i++) {
        var title = oQuickLaunchColl.get_item(i).get_title();
        console.log(title);
    }
}
function QueryFailure1(sender, args) {
    console.log('Request failed' + args.get_message());
}

Here I got error,

The URL format was invalid.

Note: I have also added item in Edit Control block of list item, also new action in Site Action menu, there I have used following code to call JavaScript function,

set_url('javascript:callNavigationAction()')

Here, my JavaScript function executed.

But when I tried the same approach for calling JavaScript function from Quick Launch Navigation it failed.

How can I call JavaScript function from Quick Launch Navigation item?

I am working with SharePoint Online.

I have a requirement where I have to add Quick Launch Navigation Item and call JavaScript function on click of the item. I am using code shown here.

Following is my code:

var oQuickLaunchColl;
function addNavigation() {
    var testt = "javascript:callNavigationAction()";
    var clientContext = new SP.ClientContext();
    var oWeb = clientContext.get_web();
    oQuickLaunchColl = oWeb.get_navigation().get_quickLaunch();
    var oNavigation = new SP.NavigationNodeCreationInformation();
    oNavigation.set_title("Start new Chat");
    oNavigation.set_url(testt);
    oQuickLaunchColl.add(oNavigation);
    clientContext.load(oQuickLaunchColl);
    clientContext.executeQueryAsync(QuerySuccess1, QueryFailure1);
}
function QuerySuccess1() {
    //Get the item count of navigation nodes and loop through it  
    var itemCount = oQuickLaunchColl.get_count();
    console.log("The navigation node details are:");
    for (var i = 0; i < itemCount; i++) {
        var title = oQuickLaunchColl.get_item(i).get_title();
        console.log(title);
    }
}
function QueryFailure1(sender, args) {
    console.log('Request failed' + args.get_message());
}

Here I got error,

The URL format was invalid.

Note: I have also added item in Edit Control block of list item, also new action in Site Action menu, there I have used following code to call JavaScript function,

set_url('javascript:callNavigationAction()')

Here, my JavaScript function executed.

But when I tried the same approach for calling JavaScript function from Quick Launch Navigation it failed.

How can I call JavaScript function from Quick Launch Navigation item?

I am working with SharePoint Online.

I have a requirement where I have to add Quick Launch Navigation Item and call JavaScript function on click of the item. I am using code shown here.

Following is my code:

var oQuickLaunchColl;
function addNavigation() {
    var clientContext = new SP.ClientContext();
    var oWeb = clientContext.get_web();
    oQuickLaunchColl = oWeb.get_navigation().get_quickLaunch();
    var oNavigation = new SP.NavigationNodeCreationInformation();
    oNavigation.set_title("Start new Chat");
    oNavigation.set_url('javascript:callNavigationAction()');
    oQuickLaunchColl.add(oNavigation);
    clientContext.load(oQuickLaunchColl);
    clientContext.executeQueryAsync(QuerySuccess1, QueryFailure1);
}
function QuerySuccess1() {
    //Get the item count of navigation nodes and loop through it  
    var itemCount = oQuickLaunchColl.get_count();
    console.log("The navigation node details are:");
    for (var i = 0; i < itemCount; i++) {
        var title = oQuickLaunchColl.get_item(i).get_title();
        console.log(title);
    }
}
function QueryFailure1(sender, args) {
    console.log('Request failed' + args.get_message());
}

Here I got error,

The URL format was invalid.

Note: I have also added item in Edit Control block of list item, also new action in Site Action menu, there I have used following code to call JavaScript function,

set_url('javascript:callNavigationAction()')

Here, my JavaScript function executed.

But when I tried the same approach for calling JavaScript function from Quick Launch Navigation it failed.

How can I call JavaScript function from Quick Launch Navigation item?

Source Link

How to call javascript function on Quick Launch Navigation Item click?

I am working with SharePoint Online.

I have a requirement where I have to add Quick Launch Navigation Item and call JavaScript function on click of the item. I am using code shown here.

Following is my code:

var oQuickLaunchColl;
function addNavigation() {
    var testt = "javascript:callNavigationAction()";
    var clientContext = new SP.ClientContext();
    var oWeb = clientContext.get_web();
    oQuickLaunchColl = oWeb.get_navigation().get_quickLaunch();
    var oNavigation = new SP.NavigationNodeCreationInformation();
    oNavigation.set_title("Start new Chat");
    oNavigation.set_url(testt);
    oQuickLaunchColl.add(oNavigation);
    clientContext.load(oQuickLaunchColl);
    clientContext.executeQueryAsync(QuerySuccess1, QueryFailure1);
}
function QuerySuccess1() {
    //Get the item count of navigation nodes and loop through it  
    var itemCount = oQuickLaunchColl.get_count();
    console.log("The navigation node details are:");
    for (var i = 0; i < itemCount; i++) {
        var title = oQuickLaunchColl.get_item(i).get_title();
        console.log(title);
    }
}
function QueryFailure1(sender, args) {
    console.log('Request failed' + args.get_message());
}

Here I got error,

The URL format was invalid.

Note: I have also added item in Edit Control block of list item, also new action in Site Action menu, there I have used following code to call JavaScript function,

set_url('javascript:callNavigationAction()')

Here, my JavaScript function executed.

But when I tried the same approach for calling JavaScript function from Quick Launch Navigation it failed.

How can I call JavaScript function from Quick Launch Navigation item?