(如果你会SHAREPOINT)这个情况就是从登录页到首页
从 Login.aspx 到 index.aspx(2页不在一个路径下)
当时是做了一个 SL的幻灯片,想实现的效果就是 当用户登录到首页的时候 自动弹出。然后当他在没退出的情况下,再次单击首页的时候,不弹出,想法是用 cookie做
login.aspx(清空cookie)--登录到首页--(判断是否存在cookie,如果不存在,弹出幻灯片)--index.aspx(给cookie赋值)--这时候,如果再次点击首页,将不会弹出
这个问题,如果login.aspx 和 index.aspx 在一个路径下,就用普通方法,就可以。但是 在sharepoint 中Login.aspx 和 index.aspx在不同的地方,所以导致需要一点点小技巧
方法1:文章:http://topic.csdn.net/u/20080130/12/9788db1d-eb7c-47b2-87c1-957046dfab6f.html
方法2:
login:
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
Code
<script type="text/javascript">
function Do() {
writeCookie("ShowNewWindow", 1, 8760);
}
if (document.all) {
window.attachEvent('onload', Do);
}
else {
window.addEventListener('load', Do, false);
}
</script>
index.aspx:
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
Code
<script src="/_layouts/script/Cookies.js" type="text/javascript"></script>
<script type="text/javascript">
function openwindow(url, name, iWidth, iHeight) {
var url; //转向网页的地址;
var name; //网页名称,可为空;
var iWidth; //弹出窗口的宽度;
var iHeight; //弹出窗口的高度;
var iTop = (window.screen.availHeight - 30 - iHeight) / 2; //获得窗口的垂直位置;
var iLeft = (window.screen.availWidth - 10 - iWidth) / 2; //获得窗口的水平位置;
window.open(url, name, 'height=' + iHeight + ',,innerHeight=' + iHeight + ',width=' + iWidth + ',innerWidth=' + iWidth + ',top=' + iTop + ',left=' + iLeft + ',toolbar=no,menubar=no,scrollbars=auto,resizeable=no,location=no,status=no');
}
function DoWindowOpen() {
if (readCookie("ShowNewWindow") == 1) {
writeCookie("ShowNewWindow", 0, 8760);
openwindow("http://web:8000/Pages/slideshow/slider.aspx", "", 960, 480);
}
}
if (document.all) {
window.attachEvent('onload', DoWindowOpen);
}
else {
window.addEventListener('load', DoWindowOpen, false);
}
</script>
Cookies.js:
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
Code
function getCookie(a)
{
var b = String(document.cookie);
var c = b.indexOf(a + "=");
if (c != -1) {
var d = b.indexOf(";", c);
d = d == -1 ? b.length : d;
c = c + a.length + 1;
if(b.charAt(c)=='"'&&b.charAt(d-1)=='"'){
c+=1;d-=1;
}
if(c>=d)
return "";
return b.substring(c, d);
}
return "";
};
function writeCookie(name, value, hours) {
var expire = "";
if (hours != null) {
expire = new Date((new Date()).getTime() + hours * 3600000);
expire = "; expires=" + expire.toGMTString();
}
document.cookie = name + "=" + escape(value) + expire+";path=/";
}
function writeUnescapeCookie(name, value, hours) {
var expire = "";
if (hours != null) {
expire = new Date((new Date()).getTime() + hours * 3600000);
expire = "; expires=" + expire.toGMTString();
}
document.cookie = name + "=" + value + expire;
}
function delCookie(name) {
var exp = new Date();
exp.setTime(exp.getTime() - 1);
if (readCookie(name) != 0)
document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
}
function readCookie(name) {
var cookieValue = "";
var search = name + "=";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search);
if (offset != -1) {
offset += search.length;
end = document.cookie.indexOf(";", offset);
if (end == -1) end = document.cookie.length;
cookieValue = unescape(document.cookie.substring(offset, end));
}
}
return cookieValue;
}