I'm working on a new design of my site and I just installed the MS live search box (http://search.live.com/siteowner). It works fine but I think its javascript conflicts with the styleswitcher code I got from (http://alistapart.com/stories/alternate/). For some reason cookies now don't remember the style from the previous page. Would anyone have any idea how to rectify this?
function setActiveStyleSheet(title) { var i, a, main; for(i=0; (a = document.getElementsByTagName("link")[i]); i++) { if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) { a.disabled = true; if(a.getAttribute("title") == title) a.disabled = false; } } }
function getActiveStyleSheet() { var i, a; for(i=0; (a = document.getElementsByTagName("link")[i]); i++) { if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title"); } return null; }
function getPreferredStyleSheet() { var i, a; for(i=0; (a = document.getElementsByTagName("link")[i]); i++) { if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("rel").indexOf("alt") == -1 && a.getAttribute("title") ) return a.getAttribute("title"); } return null; }
function createCookie(name,value,days) { if (days) { var date = new Date(); date.setTime(date.getTime()+(days*24*60*60*1000)); var expires = "; expires="+date.toGMTString(); } else expires = ""; document.cookie = name+"="+value+expires+"; path=/"; }
function readCookie(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for(var i=0;i < ca.length;i++) { var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1,c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); } return null; }
window.onload = function(e) { var cookie = readCookie("style"); var title = cookie ? cookie : getPreferredStyleSheet(); setActiveStyleSheet(title); }
window.onunload = function(e) { var title = getActiveStyleSheet(); createCookie("style", title, 365); }
var cookie = readCookie("style"); var title = cookie ? cookie : getPreferredStyleSheet(); setActiveStyleSheet(title);
That is the source of the problem. <script type="text/javascript"> <!-- window.onload=function(){ var formref=document.getElementById("switchform") indicateSelected(formref.choice) }
function MM_openBrWindow(theURL,winName,features) { //v2.0 window.open(theURL,winName,features); } //--> </script> they both using window.onload=function() to initiate on a page.
you might try something like that not gurantee it will work Change this MS deal to <script type="text/javascript"> <!-- function mssearch(){ var formref=document.getElementById("switchform") indicateSelected(formref.choice) }
function MM_openBrWindow(theURL,winName,features) { //v2.0 window.open(theURL,winName,features); } //--> </script> So we removing conflicting onload event then. in in body add <body onload="mssearch();">
Thanks for your help Dmitry but I am afraid it still doesn't work. All that happened is that the default smaller font is carried over to next pages. But really thanks for your suggestion.