Javascript running on Page tab

Anthony Levine asked on November 22, 2016 17:55

Is there any reason Javascript (added using the Javascript control) runs on the Page tab? It's preventing me from editing text in an editable text box. I now have to check whether the URL contains "/admin" before running to prevent this. To test this, add a Javascript control in the design mode on any page, add the statement alert('Test'); into the "In-line script" box. You can include the <script> tags or select to have them added and Save. Then go to the Page tab and you'll be met with an alert box. Is there a practical reason to allow Javascript to run on the Page tab?

Recent Answers


Peter M answered on November 22, 2016 18:09

Well if you want to prevent pop up in the edit mode you can do it with macro: For your javascript web part properties Behavior/Enabled you can put something like {%PortalContext.ViewMode == "LiveSite"@%} - this means your javascript alert will work only on the live site. When you edit your document you will not see the alert box.

0 votesVote for this answer Mark as a Correct answer

Jan Hermann answered on November 22, 2016 18:13 (last edited on November 22, 2016 19:46)

That's correct. As Peter mentioned, you can prevent any code to be executed only on the live site. The whole macro could look like this:

{% if (PortalContext.ViewMode == "LiveSite") { %}
HTML code including SCRIPT tags executed only on the live site
{% } %}
1 votesVote for this answer Mark as a Correct answer

Anthony Levine answered on November 22, 2016 19:45

I was under the impression that using the Javascript control would prevent Javascript from running within the admin panel on the Page tab. Thank you both for your answers.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.