[thelist] Save me from JavaScript humiliation
Fred D Yocum
fdy at mcc.org
Mon Feb 12 08:41:57 CST 2007
I am struggling with a JavaScript function which I cannot get to work.
The script should do three things
1) Stop the default action from happening (loading into the current
browser window)
2) Display a message after the link text saying appearing gradually and
disappearing "Opening in a new window"
3) Open in a new window.
In debugging, seems to be go through the script in the right order. But
... the message is not displayed and the link opens in the current window.
I have tried all sorts of configurations with little or no success. Put
aside your concerns about opening content in new windows. This is on a
internal page, indexing 600+ documents in various formats in an up to 8
level deep list of lists. I want people to be able to drill down and be
able to come back to where they were, without the page refreshing loosing
their place.
--Here is the annotated function which is assigned to links from a onload
function
function openInNewWindow() {
//Gather variable
var thisLink = this;
//Create a span
var alertMessage = document.createElement('span');
//Creat text for span
var messageText = document.createTextNode(' Opening in new window
\u2026');
//give it a class
alertMessage.setAttribute('class', 'alertText01');
//append text to span
alertMessage.appendChild(messageText);
//Apppend the message to the link
var aniAlert = thisLink.appendChild(alertMessage);
//Define two functions
// Window open called from alertBlink
function openWindow() {
var newWindow = window.open(thisLink.getAttribute('href'),
'newWindow');
newWindow.focus();
return false;
}
//Define appearing text
function alertBlink() {
//Scroll through classes that change the text from light
grey to red to display:none
alertClass = aniAlert.getAttribute('class');
if (alertClass == 'alertText01'){
aniAlert.setAttribute('class','alertText02');
}
else if (alertClass == 'alertText02'){
aniAlert.setAttribute('class','alertText03');
}
else if (alertClass == 'alertText03'){
aniAlert.setAttribute('class','alertText04');
}
else if (alertClass == 'alertText04'){
aniAlert.setAttribute('class','alertText05');
}
//If it does not have the final class repeat
if (alertClass != 'alertText05'){
setTimeout(alertBlink(), 5000);
}
//Else open window
else {
setTimeout(openWindow(), 25000);
}
}
alertBlink(); //Final of new Window open
}
---End script
You can find it in non working order here -- use the temp link at the top
of the page:
http://home.dejazzd.com/theyocum/temp/Start.html
Save me from javascript hell...
Fred D Yocum
More information about the thelist
mailing list