Weird behavior for adding "embed code" inside our classic pages and inside application pages

Steel Contributor

I am working on a new sharepoint tenant. and using the sharepoint/tenant admin i created a new Communication modern site. and i have migrated our on-premises 2013 classic team site into the new communication site, i did the migration using a third part tool named share-gate. but i got weird behavioure for the "Embed code" web part, as follow:-

 

1. inside the sharepoint online admin center site >> setting >> we have custom script disabled, as follow:-

customscript.png

2. then inside the migrated site (which is a modern communication site), i am able to add "embed code" inside existing and new classic site pages as follow:-

embdeecoe.png2. while if i edit an application page such as "lists/discussion/allitems.aspx", and i edit the page i can not add "embed code" or "script editor" web parts:-

appl.png

so i have the following question based on my above points:-

1. since we have "custom scripts" disabled inside the sharepoint admin center >> settings. then how i were able to add "embed code" web part inside my site pages?

2. why i am able to add "embed code" inside site pages, while i can not do so inside application pages?

3. if we have "custom scripts" disabled inside the sharepoint admin center >> settings. then will customs scripts be enabled or disabled inside communication sites created by sharepoint admin?

15 Replies

Hi @john john!

 

i suggest you should ask someone at the helpdesk of share-gate.com, @Mia Lohé Chung wrote here couple of articles about the migration tool, she works there.

 

Look at this: https://techcommunity.microsoft.com/t5/SharePoint/Migrate-Libraries-using-ShareGate-s-Copy-Site-Obje...

 

I am not familar with that tool. Pose your question directly to her pls.

 

Greets, Eva.

 


@Eva Vogel wrote:

Hi @john john!

 

i suggest you should ask someone at the helpdesk of share-gate.com, @Mia Lohé Chung wrote here couple of articles about the migration tool, she works there.

 

Look at this: https://techcommunity.microsoft.com/t5/SharePoint/Migrate-Libraries-using-ShareGate-s-Copy-Site-Obje...

 

I am not familar with that tool. Pose your question directly to her pls.

 

Greets, Eva.

 


but i do not think this problem is related to the migration tool, it is related to sharepoint communication site...

Have you actually tried to insert script into the page? I remember my Sharepoint site would have this option available, but soon as I added the script tag to the box and hit Ok it would prompt me to a warning telling me I couldn't.

@Deleted wrote:
Have you actually tried to insert script into the page? I remember my Sharepoint site would have this option available, but soon as I added the script tag to the box and hit Ok it would prompt me to a warning telling me I couldn't.

@Deleted

thanks a lot for the advice. now i created a classic page >> add "Embed code" , i got this 2 results:-

 

1. Inside the embed code i added pure HTML element, as follow:-

<h1 unselectable="on">test</h1>

and i were able to save the page without any issue.

 

2. While if i try to add a script element inside the "Embed code" as follow:-

<h1 unselectable="on">test</h1>
<script>
alert("123");
</script>

 

i got this error:-

This HTML cannot be inserted because you don't have access to add scriptable Web Parts in this site. Please contact your administrator if you think you should have rights to do so.

 

so can i conclude that in my case i can add "embed code" web parts, but those "embed code" need to contain HTML only?

second question, so seem i do not have "custom scripts" enabled inside our communication site (since i was not able to add <script> tags inside the "embed code"). so can i enable the custom scripts for this communication site only, without having to affect the "custom scripts" settings inside other sites, or change the settings inside the sharepoint admin center site?


 so can i conclude that in my case i can add "embed code" web parts, but those "embed code" need to contain HTML only?


It cannot contain script, hence you will be not able to use the script tag in that code. I think you can still use other tags, such as the link tag to include CSS.

 


second question, so seem i do not have "custom scripts" enabled inside our communication site (since i was not able to add <script> tags inside the "embed code"). so can i enable the custom scripts for this communication site only, without having to affect the "custom scripts" settings inside other sites, or change the settings inside the sharepoint admin center site?


Yes, you can enable custom script for that site alone. But first, you need to allow users to runcustom script. Only then, you will be able to turn on custom scripting on your site. For more information, you can check this post.

 

Regards



It cannot contain script, hence you will be not able to use the script tag in that code. I think you can still use other tags, such as the link tag to include CSS.

 


@Deletedok noted. thanks

 



Yes, you can enable custom script for that site alone. But first, you need to allow users to runcustom script. Only then, you will be able to turn on custom scripting on your site. For more information, you can check this post.

 

 


but if i enable "custom scripts" from sharepoint admin center >> setting >>

 

cs.pngthen this will enable custom scripts inside all the current site collections and all future site collections, is this correct? while in my case i only need to enable it inside a single modern communication site, so is this possible and how?

John, from my understanding, that option gives you the ability to enable custom script on your site. Turning it on will not automatically give all sites the ability to run custom scripts. Instead, it gives site owners the ability to turn on custom scripts on their site.
However, if I remember correctly, you need to run some command lines in the Powershell to enable custom scripts in a site, and only admins can run powershell commands. That means if you are the only admin of the tenant, no one will be able to enable custom scripts other than you. Again, I am not sure if this is still true or if there is another way to enable custom script, but I believe turning that on is the only way to go if you want them in your site.

@Deleted wrote:
John, from my understanding, that option gives you the ability to enable custom script on your site. Turning it on will not automatically give all sites the ability to run custom scripts. Instead, it gives site owners the ability to turn on custom scripts on their site.
However, if I remember correctly, you need to run some command lines in the Powershell to enable custom scripts in a site, and only admins can run powershell commands. That means if you are the only admin of the tenant, no one will be able to enable custom scripts other than you. Again, I am not sure if this is still true or if there is another way to enable custom script, but I believe turning that on is the only way to go if you want them in your site.

i think "custom scripts" setting in sharepoint ,, is very confusing and even reading the documentation does not cover all the cases...

Yeah John, you might be correct. Since Microsoft shifted their focus to Modern sites, they left a lot of settings belonging to classic sites lacking complete information. Good things we have all these Sharepoint blogs that can help us get where we want! Hope I could answer the topic and show you how to do it, should you decide turning on custom script is the way to go. If you have any question, let us know!

@Deleted wrote:
Hope I could answer the topic and show you how to do it, should you decide turning on custom script is the way to go. If you have any question, let us know!

so you mean it is even not clear to you how "custom scripts" works inside sharepoint online?

I mean that Microsoft could make it more clear. I have a pretty good understanding about it now, but most of the times I had to google my way into it or learn through blogs. I think here are the main keys:

 

  • First, the disclaimer. If you are planning to use modern sites, which is where Microsoft is doing its new stuff from now on, you may think about not using custom scripts, since they are not (officially) supported in modern sites. They have some warnings about security and other kinds of concerns, but I think that is main key to consider. If you stick to classic sites, you might have to use them at some point, as it extends the site functionality to a whole new level. I am more of a classic site guy and I couldn't live without them.
  • If you decided you want to use them, then you have some steps to follow. Basically, what I told before, ensure you're an admin, turn on the ability to enable custom scripts on sites, and then enable it on your site. If you're not an admin, I don't think you can have it enabled, even if you're the site owner. So that brings some kind of security, since you can track which sites have custom scripts enabled.
  • If you follow these steps, then you should be able to use scripts right away, although it may take up to 24 hours to take effect. I usually notice it is enabled when the Script Editor is available.
  • From then, you've got it all! You can script your way into basically anything you want.
  • If you chose not to use scripts, users will still be able to insert code into their pages. However, they cannot insert script into that code (HTML,CSS is all fair game).

Do you still have questions about it? Let me know!


@Deleted wrote:
  • If you decided you want to use them, then you have some steps to follow. Basically, what I told before, ensure you're an admin, turn on the ability to enable custom scripts on sites, and then enable it on your site. If you're not an admin, I don't think you can have it enabled, even if you're the site owner. So that brings some kind of security, since you can track which sites have custom scripts enabled.

@Deleted  yes i am the office 365 and sharepoint admin. but i am not sure how the "custom script" settings work at the sharepoint admin center level and on the site collection level?

for example if i enable "custom scripts" at the SP admin site, then will it affect exsisting site collections? as in my case i want "custom scripts" to stay disabled on all the site collections (future and existing site collection), while i only want to enable it inside one site collection.so is this possible? in other words can i run the below script to enable "custom scripts" on single site collection, without having to allow "custom script" from the SP admin site?:-

Connect-SPOService -Url https://YourDomain-admin.sharepoint.com
Set-SPOSite -Identity https://YourDomain.sharepoint.com/sites/YourSite -DenyAddAndCustomizePages 0

 

second question. inside this Microsoft documentation https://docs.microsoft.com/en-us/sharepoint/allow-or-prevent-custom-script   it mentioned the following about changing the "Custom scripts" at the site collection level using power-shell "If you change this setting for a user's OneDrive or a classic team site, it will be overridden by the Custom Script setting in the admin center within 24 hours." .So can i conclude that at the end all site collections regardless of their templates (modern, classic, root, personal site & self-service site) will have the same "custom scripts" settings,, as per the sharepoint admin center?, and that defining custom scripting settings at the site collection level using this script "Set-SPOsite <SiteURL> -DenyAddAndCustomizePages 0" will not be permanent change?

Fair questions, John. Let me try to make it as clear as possible.

 


@john john wrote:

@Deleted wrote:
  • If you decided you want to use them, then you have some steps to follow. Basically, what I told before, ensure you're an admin, turn on the ability to enable custom scripts on sites, and then enable it on your site. If you're not an admin, I don't think you can have it enabled, even if you're the site owner. So that brings some kind of security, since you can track which sites have custom scripts enabled.

@Deleted  yes i am the office 365 and sharepoint admin. but i am not sure how the "custom script" settings work at the sharepoint admin center level and on the site collection level?

for example if i enable "custom scripts" at the SP admin site, then will it affect exsisting site collections? as in my case i want "custom scripts" to stay disabled on all the site collections (future and existing site collection), while i only want to enable it inside one site collection.so is this possible? in other words can i run this script to enable "custom scripts" on single site collection, without having to allow "custom script" from the SP admin site?:-

 


From my understanding, enabling custom scripts in the SP Admin site won't do anything for right away. That's like saying "If they want to enable it and they have privileges to do it, they can.". So basically it is allowing your powershell code to work if you try to run it. It will not affect existing or future collections unless you explicitly use the powershell code to enable it on them. So you can allow the option in the admin site, use the powershell to enable it on your site and, as along as your or no other admin use the same powershell command, only your site would have custom scripts. However, I don't think you can achieve without allowing custom scripts. You can try to enable it on your site without allowing custom scripts, though, and see how it goes.


 

second question. inside this Microsoft documentation https://docs.microsoft.com/en-us/sharepoint/allow-or-prevent-custom-script   it mentioned the following about changing the "Custom scripts" at the site collection level using power-shell "If you change this setting for a user's OneDrive or a classic team site, it will be overridden by the Custom Script setting in the admin center within 24 hours." .So can i conclude that at the end all site collections regardless of their templates (modern, classic, root, personal site & self-service site) will have the same "custom scripts" settings,, as per the sharepoint admin center?, and that defining custom scripting settings at the site collection level using this script "Set-SPOsite <SiteURL> -DenyAddAndCustomizePages 0" will not be permanent change?


Have in mind that this note is directed to Team sites. I have no idea what might happen if you enable custom script on a publishing site, for example, and disable custom scripting in the SP admin center after that. I believe your custom scripts would stay for that site, though.

 

You don't need to take my word for it. You could always set up a developer account for free and create a tenant to test all of this stuff. Any questions, lemme know.


 


From my understanding, enabling custom scripts in the SP Admin site won't do anything for right away. That's like saying "If they want to enable it and they have privileges to do it, they can.". So basically it is allowing your powershell code to work if you try to run it. It will not affect existing or future collections unless you explicitly use the powershell code to enable it on them. So you can allow the option in the admin site, use the powershell to enable it on your site and, as along as your or no other admin use the same powershell command, only your site would have custom scripts. However, I don't think you can achieve without allowing custom scripts. You can try to enable it on your site without allowing custom scripts, though, and see how it goes.


 


@Deletedi do not think this is basically the case. as on a tenant which we manage, i got a request indicating that end users are not able to add "custom scripts" to the root site collection's pages (which is a classic team site). so what i did, is that i went to sharepoint admin center, i allow custom scripts and the end users were able to add custom scripts to the root classic team site after couple of hours!! i did not run any powershell script.

 


 

You don't need to take my word for it. You could always set up a developer account for free and create a tenant to test all of this stuff. Any questions, lemme know.


i already have a test tenant, this is not any issue. but testing this without having any base line of knowledge to start with will fail. as some "custom script" settings will be overridden after 24 hours, so what i test now , might not be the case after 24 hours + seems custom scripts will work differently on modern sites, classic sites, self created sites, root site & one drive sites ...... so if i just start testing i will not get beneficial results !!



@Deletedi do not think this is basically the case. as on a tenant which we manage, i got a request indicating that end users are not able to add "custom scripts" to the root site collection's pages (which is a classic team site). so what i did, is that i went to sharepoint admin center, i allow custom scripts and the end users were able to add custom scripts to the root classic team site after couple of hours!! i did not run any powershell script.


Woah, I did not know that was a thing. Back on my struggling days to get scripts to work, powershell would be the only way to go. I am sorry to hear it, then. As you said, testing this on a different environment may not give you beneficial results right away, although it might be good to get some knowledge on how Sharepoint behaves about this kind of stuff.

Well, at least we know that Embed Code will not work for scripts if custom scripts are not enabled. Looks like it's the only thing we can take from granted here, then.