Tuesday, June 2, 2009

javascript - moving tool tip

basic & simple code that I use to do moving tool tip.
1.javascript:


2.html:
Hello World
Span 1

reload browser ONLY once

Sometimes there's a need to reload a browser only once. This works in IE and FF.
//  Published at: scripts.tropicalpcsolutions.com
var reloaded = false;
var loc=""+document.location;
loc = loc.indexOf("?reloaded=")!=
   -1?loc.substring(loc.indexOf("?reloaded=")+
   10,loc.length):"";
loc = loc.indexOf("&")!=-1?loc.substring(0,loc.indexOf("&")):loc;
reloaded = loc!=""?(loc=="true"):reloaded;

function reloadOnceOnly() {
    if (!reloaded) 
        window.location.replace(
           window.location+"?reloaded=true");
}

//You can call this via the body tag if desired
reloadOnceOnly();

Monday, June 1, 2009

IE:fixing innerHTML - ajax callback

innerHTML can cause some problems, particularly in Internet Explorer. If you use innerHTML to add or update form elements, all sorts of screwiness can occur. Sometimes the data from the newly added elements won’t be included when the form is submitted to the server. This is a solution that works in IE:
var newdiv = document.createElement("div");
newdiv.innerHTML = xhr.responseText;
var container = document.getElementById("container");
container.appendChild(newdiv);