Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

SharePoint 2010 allowed users to put JavaScript straight into the Quick Launch as a link.

Doing this in SharePoint 2013 causes an error when you try to save. I have some sites upgraded from 2010 that have kept their Quick Launch JavaScript but I can't edit or add more. Does anyone know a workaround?

share|improve this question

1 Answer 1

It is possible to do this with PowerShell. This does require the "Minimal Download Strategy" feature to be disabled on the site in question, otherwise you will receive an error when clicking on the link. Note, this might also be required for other links such as mailto: or file:// to work properly.

In the SharePoint Management Management shell you can do something similar to the following.

    #Add a new link
    $url = "http://sharepoint.domain.com"
    $spWeb = Get-SPWeb -Identity "$($Url)" -ErrorAction SilentlyContinue
    # Add link
    # The format is DisplayName, link, is external (true/false)
    $node = New-Object Microsoft.SharePoint.Navigation.SPNavigationNode("Test Link", "javascript:alert('test alert')", $true)
    $spWeb.Navigation.QuickLaunch.AddAsFirst($node)
    $spWeb.Dispose()

    #Update existing link
    $spWeb = Get-SPWeb -Identity "$($Url)" -ErrorAction SilentlyContinue
    # Update link
    # Select the menu if necessary
    $selLink = $spWeb.Navigation.QuickLaunch | ? {$_.Title -eq "LinkName"}

    $selLink.Url = "javascript:alert('test')"
    $selLink.Update()

    $spWeb.Dispose()

If you wanted to updated the Top Navigation, you can replace

$spWeb.Navigation.QuickLaunch with $spWeb.Navigation.TopNavigationBar

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.