2014-03-13 44 views
0

在SharePoint 2013中在Sharepoint中,您可以在用户注销时运行脚本

我有一个显示免责声明的脚本。这个脚本创建了一个cookie,我想删除这个cookie或者在用户注销时将其设置为过期。

这可能吗?

<p align="center">DISCLAIMER GOES HERE</p> 
<script type="text/javascript" language="javascript"> 
var agreement = GetCookie(); 

// checks for cookie and displays disclaimer alert if new user 
if(agreement=="") 
    { 
    var decision = confirm("DISCLAIMER: GOES HERE \n\nClick Ok if you agree to the disclaimer or click Cancel to close this window. \n"); 
      if(decision == true) 
        { 
        // writes a cookie 
        var expiredays = 7; 
        var exdate=new Date() 
        exdate.setDate(exdate.getDate()+expiredays) 
        document.cookie="PartnerAgreement"+ "=" +escape("Agree To Disclaimer")+ 
        ((expiredays==null) ? "" : "; expires="+exdate.toGMTString()) 
        } 
        else 
        { 
        // redirect 
        window.location = "/_layouts/signout.aspx"; 

        // or close the browser window 
        //window.opener='x'; 
        //window.close(); 
        } 
    } 

// gets the Cookie if it exists 
function GetCookie() 
    { 
    if (document.cookie.length>0) 
      { 
      c_name = "PartnerAgreement"; 
      c_start=document.cookie.indexOf(c_name + "=") 
      if (c_start!=-1) 
        { 
        c_start=c_start + c_name.length+1 
        c_end=document.cookie.indexOf(";",c_start) 
        if (c_end==-1) c_end=document.cookie.length 
        return agreement = unescape(document.cookie.substring(c_start,c_end)) 
        } 
      } 
      return ""; 
    } 

回答

1

你当然可以尝试。当您按“注销”时,您将被重定向到C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\TEMPLATE\LAYOUTS文件夹中的SignOut.aspx页面。尝试在window.close()声明之前将代码添加到其脚本块。更改aspx页后不要忘记执行iisreset。

+0

编辑布局文件夹中的默认SharePoint页面是一种不好的做法。您最好创建一个新页面,并将其设置为带有SharePoint Management Shell的新注销页面:“Set-SPCustomLayoutsPage -identity”注销“-RelativePath”/_layouts/CustomSignout/Signout.aspx“-WebApplication”http:// yourwebapplication “'。但除此之外,我认为这将是一条路。 – Jan

+0

是的,在布局文件夹中编辑标准页面通常不是很好,但在这种情况下,他需要与标准页面以及一些自定义脚本完全相同的功能。如果他只是制作标准页面的副本,那么它与你的建议没有任何区别。除了他不需要运行任何PowerShell脚本。 –

+0

这是正确的,但对于任何SharePoint更新,如果只编辑页面,则可能会覆盖更改。 – Jan

相关问题