Hey, please help me, this html file run normally in other browser but Firefox.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> 
<head> 
<title>Hello everyone... </title> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
<!-- Redirect webpage <meta http-equiv="refresh" content="2; url=/web/forum/vanilla" /> --> 
</head> 
<body> 
<script language="javascript" type="text/javascript"> 
function clickMe(){
var clickLink = document.getElementById("link2Click");
clickLink.onClick = promptWhatsName();
} // End function clickMe
function promptWhatsName(){
var yourName = prompt("What is your name?", "Your name here...");
if (yourName == null || yourName == ""){
alert("You must enter your name.");
return false;
}
if (yourName.length < 10){
alert("Your name must be over 10 character in length.");
return false;
} else {
document.write("Hello, " + yourName);
return true;
}; // End if
}// End function promptWhatsName
</script> 
<!-- no script for old browser --> 
<noscript> 
Your browser doesn't support Javascript.
</noscript> 
<a href="javascript:;" id="link2Click" onClick="clickMe()">Click me!</a> 
</body> 
</html>

See more detail in this video: http://www.youtube.com/watch?v=dS1-_NLDBYU
I tested in other Firefox on other OS (Windows XP).
And I tried href="#", it doesn't show me result in Firefox like Chrome, Konqueror

Change line 14 from this: clickLink.onClick = promptWhatsName(); to this: clickLink.onclick = promptWhatsName;

Thanks, I tried but it still loading in Firefox.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Hello everyone... </title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<!-- Redirect webpage <meta http-equiv="refresh" content="2; url=/web/forum/vanilla" /> -->
</head>
<body>
<script language="javascript" type="text/javascript">
window.onload = clickMe;
function clickMe(){
var clickLink = document.getElementById("link2Click");
clickLink.onclick = promptWhatsName;
} // End function clickMe
function promptWhatsName(){
var yourName = prompt("What is your name?", "Your name here...");
if (yourName == null || yourName == ""){
alert("You must enter your name.");
return false;
}
if (yourName.length < 10){
alert("Your name must be over 10 character in length.");
return false;
} else {
document.write("Hello, " + yourName);
}; // End if
}// End function promptWhatsName
</script>
<!-- no script for old browser -->
<noscript>
Your browser doesn't support Javascript.
</noscript>
<a href="javascript:;" id="link2Click">Click me!</a>
</body>
</html>

Maybe Firefox have a problelm?

This code is doesn't run normally in firefox at all. Chrome is OK.
I think the problem here is href="javascript:;", maybe Firefox doesn't understand this?

<html>
<head>
<title>Hello everyone</title>
</head>

<body>
<script language="javascript" type="text/javascript">
window.onload = initAll;
function initAll(){
actRedirect();
}
function actRedirect(){
var actLink = document.getElementById("activeRedirect");
actLink.onclick = redirectNow;
}
function redirectNow(){
window.setTimeout("window.location.href='http://google.com'", 5000);
document.write("Please wait, you will be redirect to google soon!");
}
</script>
<a href="javascript:;" id="activeRedirect"> Redirect to Google now.</a>
</body>
</html>

Your problem is that you keep using document.write AFTER the page has loaded. You should only use it WHILE the page is still loading. Try creating a div with an id and whatever you intend to put via document.write, instead insert it into the div. Also, on the <a> tag, just use href="#" instead of href="javascript:" - ex:

<html>
<head>
<title>Hello everyone</title>
</head>
<body>
<script type="text/javascript">
window.onload = initAll;
function initAll(){
actRedirect();
}
function actRedirect(){
var actLink = document.getElementById("activeRedirect");
actLink.onclick = redirectNow;
}
function redirectNow(){
 window.setTimeout(function(){window.location.href='http://google.com';}, 5000);
 document.getElementById('target').innerHTML="Please wait, you will be redirect to google soon!";
}
</script>
<div id="target"></div>
<a href="#" id="activeRedirect"> Redirect to Google now.</a>
</body>
</html>
commented: extractly +0

Ow, thanks, so helpful, I'm new in Javascript, it seem like Chrome is not like Firefox. Problem resolved :)

Glad to help.

Regards,
Hielo

PS: Don't forget to mark the thread as solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.