0

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

2
Contributors
6
Replies
8
Views
6 Years
Discussion Span
Last Post by hielo
1

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

0

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?

Edited by moonknight33: n/a

0

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>

Edited by moonknight33: n/a

1

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>
Votes + Comments
extractly
0

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

Edited by moonknight33: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.