Forum Moderators: open
Very sincerely
Marc
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>delay</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="txt/javascript">
<script type="text/javascript">
function goURL(url){
setTimeout(function(){window.location.href=url},100)
}
</script>
</head>
<body>
<a href="http://www.google.com"
onclick="goURL(this.href);return false">
mylink
</a>
</body>
</html>
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>delay linked js</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="txt/javascript">
<script src="mylinkDelayLinked.js" type="text/javascript">
</head>
<body>
<a href="http://www.google.com"
onclick="goURL(this.href);return false">
mylink
</a>
</body>
</html>
function goURL(url){
setTimeout(function(){window.location.href=url},10000)
}
JavaScript attempt one
function goURL(url){
setTimeout(function(){window.location.href=url},10000)
};
function onclickThis(x) {
onclick="goURL(x)";
return false;
};
widows.onload () {
document.getElementById("mylinkID").onclick.onclickThis(this.href);
}
function goURL(url){
setTimeout(function(){window.location.href=url},10000)
};
function onclickThis(x) {
onclick="goURL(x)";
return false;
};
widows.onload () {
document.getElementById("mylinkID")onclick=onclickThis(this.href);
}
function goURL(url){
setTimeout(function(){window.location.href=url},10000)
};
function onclickThis(x) {
onclick="goURL(x)";
return false;
};
widows.onload () {
document.getElementById("mylinkID")onclick=onclickThis(this.href);
}
function goURL(url){
setTimeout(function(){window.location.href=url},10000)
};
function onclickThis(x) {
window.location = this.href;
onclick="goURL(x)";
return false;
};
widows.onload () {
document.getElementById("mylinkID")onclick=onclickThis;
}
Sincerely
Marc
onclick="goURL(this.href);return false"
translates to
function fix() {
var el = document.getElementById("mylinkID");
el.onclick = 'goURL("' + el.href + '");return false';
}
may be ok to use window.onload ( not widows.onload (sic) ) I would use
<body onload="fix()" >
html
<html>
<head>
<title>loction delay almost linked</title>
<title>delay linked js</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="txt/javascript">
<script src="locationDelayAllMostLinked.js" type="text/javascript">
</head>
<body onload="fix()">
<a href="http://www.google.com" id="mylinkID">
mylink
</a>
</body>
</html>
javaScript
function goURL(url){
setTimeout(function(){window.location.href=url},10000)
};
function fix() {
var el = document.getElementById("mylinkID");
el.onclick = 'goURL("' + el.href + '");return false';
};
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>delay</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="txt/javascript">
<script type="text/javascript">
function goURL(url){
setTimeout(function(){window.location.href=url},100)
}
</script>
</head>
<body>
<a href="http://www.google.com"
onclick="goURL(this.href);return false">
mylink
</a>
</body>
</html>
HTML
<html>
<head>
<title>loction delay almost linked</title>
<title>delay linked js</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="txt/javascript">
<script src="locationDelayAllMostLinked.js" type="text/javascript">
</script>
</head>
<body onload="fix()">
<a href="#" id="mylinkID">
mylink
</a>
</body>
</html>
function goURL(url){
setTimeout(function(){window.location.href=url},10000)
};
function fix() {
var el = document.getElementById("mylinkID");
el.onclick = function(){goURL(this.href);return false;};
};
window.onload = function () {
document.getElementById("someID").onclick=someFunctionName("SomeParameterToPass");
}
el.onclick = function(){goURL(this.href);return false;};
window.onload = function () {
document.getElementById("someID").onclick=function(){ someFunctionName ("SomeParameterToPass");};
}
My sincere thanks
Marc
onclick = someFunctionName( ... );
is invalid as RHS can not be an expression
So you are correct, the 1st window.onload is bad and the 2nd Ok.
As for passing parameters, parameters into the onclick function are not under our control. within this function we can refer to literals, "this", and global variables (properties of window) are fine, but dont do this
function xx() {
var fred = 12;
something.onclick = function () ( ... fred ... };
}
if you realy realy need parameters look at currying if you dare [webmasterworld.com...]
Instead of having the event handler on the body element in your HTML...
<body onload="fix()">
You could have it in your external JS file...
window.onload = fix; // NB: No '()'
And leave your <body> element empty.
If you wanted to attach more than one function to the window.onload event then you could do something like....
window.onload = function() {
fix();
secondFunction();
thirdFunction();
} Effectively assigning 1 function that calls all the others.