所以我的代码在Firefox中完美运行,但我的外部pop.js文件不会在Chrome或IE中加载。 javascript控制台给我错误“Uncaught ReferenceError:popup is not defined mywebsite.com/:26 onload”但是我有点迷失,无法真正看到我应该改变什么。希望有人可以帮我解决一个相对容易的问题。
外部pop.js代码:
function toggle(div_id) {
var el = document.getElementById(div_id);
if ( el.style.display == 'none' ) { el.style.display = 'block';}
else {el.style.display = 'none';}
}
function popup(windowname) {
toggle('blanket');
toggle(windowname);
} window.onload = function() {
setTimeout(function() {
document.getElementById('popUpDiv').style.display = 'block';
}, 2000);
}
标题中的Javascript:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>1328 Matches Found!</title>
<link href="css/style1.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/pop.js"></script>
<script type="text/javascript">
function sorry() {
document.getElementById('q3').style.display='none';
document.getElementById('q4').style.display='inline';
setTimeout("document.getElementById('q4').style.display='none';document.getElementById('q5').style.display='inline';",3000);
setTimeout("document.getElementById('q5').style.display='none';document.getElementById('q6').style.display='inline';",5500);
setTimeout("document.getElementById('q6').style.display='none';document.getElementById('q7').style.display='inline';",8000);
setTimeout("document.getElementById('q7').style.display='none';document.getElementById('q8').style.display='inline';",10500);
setTimeout("window.location='http://externallink.com/file.php';",12500);
}
</script>
<script language="JavaScript" src="http://j.maxmind.com/app/geoip.js"></script>
</head>
Javascript in body:
<body onload="popup('popUpDiv')">
<div id="container">
<div id="mainContent">
<div id="blanket" style="display:none;"></div>
<div id="popUpDiv" style="display:none;">
<div class="popup-content">
<div class="headline">Vestibulum id ligula porta felis euismod semper. <script language="JavaScript">document.write(geoip_city());</script>!</div>
<div class="date">
<script type="text/javascript">
<!--
// Array of day names
var dayNames = new Array("Sunday","Monday","Tuesday","Wednesday",
"Thursday","Friday","Saturday");
// Array of month Names
var monthNames = new Array(
"January","February","March","April","May","June","July",
"August","September","October","November","December");
var now = new Date();
document.write(dayNames[now.getDay()] + ", " +
monthNames[now.getMonth()] + " " +
now.getDate() + ", " + now.getFullYear());
// -->
</script>
</div>
<div class="pre-sell-text">
Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor. Donec ullamcorper nulla non metus auctor fringilla. Morbi leo risus, porta ac consectetur ac, vestibulum at eros. Maecenas sed diam eget risus varius blandit sit amet non magna. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.
</div>
<div class="footer">
<div class="ad"><img src="images/boot01.jpg" width="110" height="225" alt="" /></div>
<div class="questionnaire">
<table width="450" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="299"><div id="q1" name="q1" onclick="document.getElementById('q1').style.display='none';document.getElementById('q2').style.display='inline';" style="vertical-align: text-top;">
<center>
Question 1 of 3:
<h1><p>Cras justo odio, dapibus ac facilisis in, egestas eget quam.</p></h1>
<br />
<span style="font-size: 24px;"><a href="#">
<div id="yesdiv" onclick="document.getElementById('q1').style.display='none';document.getElementById('q2').style.display='inline';">Yes
<input onclick="document.getElementById('q1').style.display='none';document.getElementById('q2').style.display='inline';" type="radio" />
</div>
</a> <a href="#">
<div id="yesdiv" onclick="document.getElementById('q1').style.display='none';document.getElementById('q2').style.display='inline';">No
<input onclick="document.getElementById('q1').style.display='none';document.getElementById('q2').style.display='inline';" type="radio" />
</div>
</a></span>
</center>
</div>
<div id="q2" name="q2" onclick="document.getElementById('q2').style.display='none';document.getElementById('q3').style.display='inline';" style="vertical-align: text-top;">
<center>
Question 2 of 3:
<h1><p>Cras justo odio, dapibus ac facilisis in, egestas eget quam.</p></h1>
<br />
<span style="font-size: 24px; vertical-align: text-top;"><a href="#">
<div id="yesdiv" onclick="document.getElementById('q2').style.display='none';document.getElementById('q3').style.display='inline';">Female
<input onclick="document.getElementById('q2').style.display='none';document.getElementById('q3').style.display='inline';" type="radio" />
</div>
</a> <a href="#">
<div id="yesdiv">Male
<input onclick="document.getElementById('q2').style.display='none';document.getElementById('q3').style.display='inline';" type="radio" />
</div>
</a></span>
</center>
</div>
<div id="q3" name="q3" onclick="sorry();" style="vertical-align: text-top;">
<center>
Question 3 of 3:
<h1><p>Cras justo odio, dapibus ac facilisis in, egestas eget quam.</p></h1>
<br />
<span style="font-size: 24px; vertical-align: text-top;"><a href="#">
<div id="yesdiv">Yes
<input onclick="sorry();" type="radio" />
</div>
</a> <a href="#">
<div id="yesdiv">No
<input onclick="sorry();" type="radio" />
</div>
</a></span>
</center>
</div>
<div id="q4" name="q4" style="vertical-align: text-top;">
<center>
<h1><p>Cras justo odio, dapibus ac facilisis in, egestas eget quam.</p></h1>
<br />
<img src="images/loading4.gif" alt="4" />
</center>
</div>
<div id="q5" name="q5" style="vertical-align: text-top;">
<center>
<h1><p>Cras justo odio, dapibus ac facilisis in, egestas eget quam.</p></h1>
<br />
<img src="images/loading4.gif" alt="3" /><br />
<br />
<span style="font-size: 18px;"><p>Cras justo odio, dapibus ac facilisis in, egestas eget quam.</p></span><img src="images/check.png" width="18" height="18" alt="" />
</center>
</div>
<div id="q6" name="q6" style="vertical-align: text-top;">
<center>
<h1><p>Cras justo odio, dapibus ac facilisis in, egestas eget quam.</p></h1>
<br />
<img src="images/loading4.gif" alt="2" /><br />
<br />
<span style="font-size: 18px;"><p>Cras justo odio, dapibus ac facilisis in, egestas eget quam.</p></span><img src="images/check.png" width="18" height="18" alt="9" /><br />
<span style="font-size: 18px;">1328 Matches Found in <script language="JavaScript">document.write(geoip_city());</script>!</span><img src="images/check.png" width="18" height="18" alt="8" /><br />
</center>
</div>
<div id="q7" name="q7" style="vertical-align: text-top;">
<center>
<h1><p>Cras justo odio, dapibus ac facilisis in, egestas eget quam.</p></h1>
<br />
<img src="images/loading4.gif" alt="1" /><br />
<br />
<span style="font-size: 18px;"><p>Cras justo odio, dapibus ac facilisis in, egestas eget quam.</p></span><img src="images/check.png" width="18" height="18" alt="7" /><br />
<span style="font-size: 18px;"><p>Cras justo odio, dapibus ac facilisis in, egestas eget quam.</p></span><img src="images/check.png" width="18" height="18" alt="6" /><br />
<span style="font-size: 18px;"><p>Cras justo odio, dapibus ac facilisis in, egestas eget quam.</p></span><img src="images/check.png" width="18" height="18" alt="5" /><br />
</center>
</div>
<div id="q8" name="q8" style="vertical-align: text-top;">
<center>
<h1><p>Cras justo odio, dapibus ac facilisis in, egestas eget quam.</p></h1>
<br />
<span style="font-size: 18px;"><p>Cras justo odio, dapibus ac facilisis in, egestas eget quam.</p></span><img src="images/check.png" width="18" height="18" alt="4" /><br />
<span style="font-size: 18px;"><p>Cras justo odio, dapibus ac facilisis in, egestas eget quam.</p></span><img src="images/check.png" width="18" height="18" alt="3" /><br />
<span style="font-size: 18px;"><p>Cras justo odio, dapibus ac facilisis in, egestas eget quam.</p></span><img src="images/check.png" width="18" height="18" alt="2" /><br />
<span style="font-size: 18px;"><p>Cras justo odio, dapibus ac facilisis in, egestas eget quam.</p></span><img src="images/check.png" width="18" height="18" alt="1" /><br />
</center>
</div></td>
</tr>
</table>
</div>
<div class="ad"><img src="images/boot02.jpg" width="110" height="225" alt="" /></div>
</div>
</div>
</div>
</div>
</div>
感谢您的帮助。