[thelist] Is Target dead

brian cummiskey brian at hondaswap.com
Fri Jun 18 09:10:08 CDT 2004


Sarah Sweeney wrote:

> Chris Price wrote:
>
>> I recently attempted to validate an XHTML1.0 strict page with W3C and it
>> winced at Target so I got the page to open in a new window using 
>> JavaScript.
>
> Although personally, I prefer to use class="external" rather than the 
> suggested rel="external".


I have also run into this same issue many a times.

I faux-solved the problem by including a global.js on all my pages.  I 
didn't write it...  can't remember where i got it from a year ago or 
so...   It includes targeting, style sheet on/off and a centered pop up 
function basically, it looks like so:

The target attribute is added by javascript on execution time, so to 
speak.  while, still not a "solution" it will still let you validated as 
strict, and will keep all non-yourdomain.com links to open in their own 
windows.

HTH-

<script type="text/javascript" src="/global.js"></script>


-----------------------
---- GLOBAL.JS ----





// ||||||||||||||||||||||||||||||||||||||||||||||||||
// onLoadListener

onLoadFuncs = new Array();
function addOnLoad(func){
    onLoadFuncs[onLoadFuncs.length] = func;
}
function runOnLoad(){
    for(i in onLoadFuncs){
        eval(onLoadFuncs[i]+"()");
    }
}
window.onload = runOnLoad;

// Example: addOnLoad("someFunction");

// ||||||||||||||||||||||||||||||||||||||||||||||||||
// Open external links in a new window

function handleExternalLinks(){
    var anchors = document.getElementsByTagName("a");
    var i, href;
    for(i=0; i < anchors.length; i++){
        if(!anchors[i].href) continue;
        href = anchors[i].href;
       
        if(href.indexOf("yourdomain.com") == -1){ // Href is not a file 
on my server
            if(href.indexOf("javascript:") == -1){ // Href is not a 
javascript call
                if(!anchors[i].onclick){ // Href does not have an 
onclick event
                    if(href.indexOf("mailto:") == -1){ // Href is not a 
mailto:
                        if(href.indexOf("http://") != -1){ // Href is 
not relative (for Safari)
                            anchors[i].setAttribute("target","_blank");
                        }
                    }
                }
            }
        }
    }
}
if(document.getElementsByTagName){
    addOnLoad("handleExternalLinks");
}

// ||||||||||||||||||||||||||||||||||||||||||||||||||
// Centered pop-up window

function openWindow(url, name, width, height, scroll){
    var x = (screen.availWidth-width)/2;
    var y = (screen.availHeight-height)/2;
    scroll = scroll ? "scrollbars=yes,resizable=yes," : 
"scrollbars=no,resizable=no,";
    
window.open(url,name,"toolbar=no,location=no,status=no,menubar=no,"+scroll+"width="+width+",height="+height+",screenX="+x+",screenY="+y+",top="+y+",left="+x);
}

// ||||||||||||||||||||||||||||||||||||||||||||||||||
// Fix Explorer Mac overflow bug

function beforeOnLoad(){
    var agent = navigator.userAgent.toLowerCase();
    if(agent.indexOf("mac") != -1 && document.all && 
document.getElementsByTagName){
        if(document.body.clientHeight > 500){
            document.getElementsByTagName("body")[0].style.overflow = 
"hidden";
        }
    }
}

// ||||||||||||||||||||||||||||||||||||||||||||||||||

// call like:  <a href="javascript:swapstyle();">Toggle CSS</a>
function swapstyle() {
    var i=0;
    if(document.styleSheets.length>0) {
        cs=!document.styleSheets[0].disabled;
        for(i=0;i<document.styleSheets.length;i++)
            document.styleSheets[i].disabled=cs;
        };
    void(cs=true);
}



More information about the thelist mailing list