MenuItemCustomAction popup window problem
-
06-10-2020 - |
Question
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomAction Id="c4b14799-8b38-4951-a24b-1545262b1056.MenuItemCustomAction1"
RegistrationType="List"
RegistrationId="101"
Location="EditControlBlock"
Sequence="10001"
Title="Popup;">
<UrlAction Url="~appWebUrl/Pages/Default.aspx?{StandardTokens}&SPListItemId={ItemId}&SPListId={ListId}&SPSource= {Source}&SPListURLDir={ListUrlDir}&SPItemURL={ItemUrl}" />
</CustomAction>
</Elements>
When I try:
Url="javascript:window.open('http://www.google.com','_blank')"
It encounters error:
Error occurred in deployment step 'Install app for SharePoint': There were errors when validating the App Package.
I want the target site to appear on a new window/ popup.
La solution
The same problem is already asked here: Call JavaScript function for a custom action in an app for SharePoint 2013
to cite the same MSDN article:
CustomAction cannot contain JavaScript: Any UrlActions or CommandActions must be a URL to navigate to. The URL can be parameterized with normal custom actions tokens in addition to the app-specific tokens.
The question is: What do you want to achieve?
When you just want to use a popup then you could open a Modal Dialog and link to a page inside of your app which executes what you want to do (for example open google.com). So your xml should propably look like this
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomAction Id="c4b14799-8b38-4951-a24b-1545262b1056.MenuItemCustomAction1"
RegistrationType="List"
RegistrationId="101"
Location="EditControlBlock"
Sequence="10001"
Title="Popup;"
HostWebDialog="true"
HostWebDialogHeight="500"
HostWebDialogWidth="800">
<UrlAction Url="~appWebUrl/Pages/MyPageToGoogle.aspx" />
</CustomAction>
</Elements>
I haven't tested it but it should work. Also described here: http://www.codeproject.com/Articles/754808/Open-SharePoint-App-Url-as-a-Modal-Dialog-in-Share
Update:
In your custom action example you refer to the following page:
<UrlAction Url="~appWebUrl/Pages/Default.aspx?{StandardTokens}...">
You say the popup doesn' show the page. Propably you get the following error
if that happens you need check on that page if you have the following tag inside:
<WebPartPages:AllowFraming ID="AllowFraming" runat="server" />
If not then inlcude it in the first line of this tag:
<asp:Content ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server">
<WebPartPages:AllowFraming ID="AllowFraming" runat="server" />
** other stuff **
</asp:Content>