最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Script only executing on Edit Mode-Sharepoint Page - Stack Overflow

programmeradmin4浏览0评论

I have a script attached to a CEWP which only executes when I am on edit mode and does nothing when I save the page.

<script src=".10.2/jquery.min.js"></script>
<script type="text/javascript">         
function openDialogBox(Url)  

{    
    var ModalDialogOptions = { url:Url, width: 600, height: 500, showClose: true, allowMaximize: true};     
    SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', ModalDialogOptions); 
} 

(function($){    
   $('.ms-acal-month').ready(function () {

setTimeout(function() { 

$('a[href*="DispForm.aspx"]').each(function() { 

$(this).attr('onclick', 'openDialogBox("' +  $(this).attr('href') + '")'); 

//$(this).attr('onclick', ' '); 

//alert($(this).attr('href')); 
}); 

$('a[href*="DispForm.aspx"]').each(function() { 

$(this).attr('href','javascript:openDialogBox("' +  $(this).attr('href') + '")'); 

}); 

}, 3000); 

}); 
})(jQuery);    
</script>

if it is relevant, this is what I a trying to achieve with then script:

I am on SharePoint online 2013. I have a form which has an event calendar displayed in a calendar view. If a user wants to edit an already added event that is showing on the calendar, I run into a bit of an issue. -the cell displaying the event shows the title of the event and it is hyperlinked. If the user double clicks the cell (in an empty space), he gets transferred as I want it to be to the default display page. However, if he happens to click on the hyperlinked title, the default display page is not open but the actual whole item

The reason I want the default display form to be opened at all times, is because I have a custom script there which hides/Show fields

Many thanks in advance Ijlal

I have a script attached to a CEWP which only executes when I am on edit mode and does nothing when I save the page.

<script src="https://ajax.googleapis./ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">         
function openDialogBox(Url)  

{    
    var ModalDialogOptions = { url:Url, width: 600, height: 500, showClose: true, allowMaximize: true};     
    SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', ModalDialogOptions); 
} 

(function($){    
   $('.ms-acal-month').ready(function () {

setTimeout(function() { 

$('a[href*="DispForm.aspx"]').each(function() { 

$(this).attr('onclick', 'openDialogBox("' +  $(this).attr('href') + '")'); 

//$(this).attr('onclick', ' '); 

//alert($(this).attr('href')); 
}); 

$('a[href*="DispForm.aspx"]').each(function() { 

$(this).attr('href','javascript:openDialogBox("' +  $(this).attr('href') + '")'); 

}); 

}, 3000); 

}); 
})(jQuery);    
</script>

if it is relevant, this is what I a trying to achieve with then script:

I am on SharePoint online 2013. I have a form which has an event calendar displayed in a calendar view. If a user wants to edit an already added event that is showing on the calendar, I run into a bit of an issue. -the cell displaying the event shows the title of the event and it is hyperlinked. If the user double clicks the cell (in an empty space), he gets transferred as I want it to be to the default display page. However, if he happens to click on the hyperlinked title, the default display page is not open but the actual whole item

The reason I want the default display form to be opened at all times, is because I have a custom script there which hides/Show fields

Many thanks in advance Ijlal

Share Improve this question asked Oct 28, 2013 at 9:44 ijlalijlal 333 silver badges8 bronze badges 4
  • If your script is only running when you're editing the page, the most likely cause is that your CEWP is hidden. One way to verify this would be to view the source of your page when not editing it and search for your code. Is that the case? If so, instead of hiding your CEWP set its title and border to none and leave it unhidden. – Aron Foster Commented Oct 28, 2013 at 19:17
  • Thanskfor feedback Aron..I just checked my CEWP and the hidder option is selected bydefault and grayed out that I cant change it..Would there be some other way to insert the script above on the page ? – ijlal Commented Oct 29, 2013 at 10:21
  • You might be able to change the visibility using SharePoint Designer, either with the Web Part ribbon or directly in the aspx code. You could also try making a new page and adding the event calendar and CEWP to that. – Aron Foster Commented Oct 29, 2013 at 14:17
  • It may also help,SharePoint Script Editor only works in Edit Mode it shows all mon solution for this issue! – Mohamed Commented Jul 16, 2020 at 5:27
Add a ment  | 

1 Answer 1

Reset to default 5

Add type="text/javascript" to your first script tag referencing the library and it should work. It did for me.

As it turns out, the type="text/javascript" attribute is extremely important. I had left it out of the <script> tag referencing the javascript library I was using (Angular in my case, jQuery in yours) and experienced exactly the same behavior - the angular code was executing when the page was in edit mode but was not even being called when the page was in view mode.

I realize this is an older post, but I just had a similar issue and found a resolution to my problem I thought I'd share. Hope it helps future Google searchers.

发布评论

评论列表(0)

  1. 暂无评论