admin管理员组文章数量:1431018
I've defined a function named parseURL in javascript in the head of my file, and I have a button set so that when it is clicked, it should call said function. However, for some reason my debugger is telling me that parseURL is not defined. The exact error is "Uncaught ReferenceError: parseURL is not defined"
<HTML xmlns="">
<HEAD>
<link rel="stylesheet" href="../css/style.css" type="text/css" />
<TITLE>
Pic Grabber (javascript)
</TITLE>
<script type="text/javascript" src="linkedURL.js" />
<script type="text/javascript">
var Page = {};
Page.currentURL = null;
Page.link = document.getElementById("link");
/*
###################################
# The function that "doesn't exist"
###################################
*/
function parseURL(){
Page.url = document.getElementById("url").value;
if(!checkValidURL(Page.url)){
alert("Must Enter a valid URL");
}
Page.link.innerHTML = Page.url;
return true;
}
function checkValidURL(url){
var request = false;
if (window.XMLHttpRequest) {
request = new XMLHttpRequest;
}
else if (window.ActiveXObject) {
request = new ActiveXObject("Microsoft.XMLHttp");
}
else{
alert("FAIL");
}
if (request) {
request.open("GET", url);
if (request.status == 200) {
return true;
}
}
return false;
}
</script>
</HEAD>
<BODY>
<div class="wrap">
<h1><a href="#">My Database</a></h1>
<ul id="menu">
<li><a href="../index.php">Home</a></li>
<li><a href="../upload.php">Upload</a></li>
<li><a href="#">Advanced Search</a></li>
<li><a href="#">My Profile</a></li>
</ul>
<div class="clear"></div>
<div id="left">
<a href="#" id="link"></a>
</div>
<div id="right">
<div class="box">
<form id="input">
<p>URL:</p><br/>
<input type="text" id="url" /><br />
#################################
# This is where the error appears
#################################
<input type="button" id="getButton" value="Get Pics" onclick="parseURL()" />
<input type="button" id="back" value="<< Back" onclick="back()" disabled="true"/>
<input type="button" id="next" value="Next >>" onclick="next()" disabled="true"/>
</form>
</div>
</div>
</div>
</BODY>
</HTML>
It seems like it should be an easy fix, I've tried a bunch of things though and nothing seems to be working. Any help is appreciated.
I've defined a function named parseURL in javascript in the head of my file, and I have a button set so that when it is clicked, it should call said function. However, for some reason my debugger is telling me that parseURL is not defined. The exact error is "Uncaught ReferenceError: parseURL is not defined"
<HTML xmlns="http://www.w3/1999/xhtml">
<HEAD>
<link rel="stylesheet" href="../css/style.css" type="text/css" />
<TITLE>
Pic Grabber (javascript)
</TITLE>
<script type="text/javascript" src="linkedURL.js" />
<script type="text/javascript">
var Page = {};
Page.currentURL = null;
Page.link = document.getElementById("link");
/*
###################################
# The function that "doesn't exist"
###################################
*/
function parseURL(){
Page.url = document.getElementById("url").value;
if(!checkValidURL(Page.url)){
alert("Must Enter a valid URL");
}
Page.link.innerHTML = Page.url;
return true;
}
function checkValidURL(url){
var request = false;
if (window.XMLHttpRequest) {
request = new XMLHttpRequest;
}
else if (window.ActiveXObject) {
request = new ActiveXObject("Microsoft.XMLHttp");
}
else{
alert("FAIL");
}
if (request) {
request.open("GET", url);
if (request.status == 200) {
return true;
}
}
return false;
}
</script>
</HEAD>
<BODY>
<div class="wrap">
<h1><a href="#">My Database</a></h1>
<ul id="menu">
<li><a href="../index.php">Home</a></li>
<li><a href="../upload.php">Upload</a></li>
<li><a href="#">Advanced Search</a></li>
<li><a href="#">My Profile</a></li>
</ul>
<div class="clear"></div>
<div id="left">
<a href="#" id="link"></a>
</div>
<div id="right">
<div class="box">
<form id="input">
<p>URL:</p><br/>
<input type="text" id="url" /><br />
#################################
# This is where the error appears
#################################
<input type="button" id="getButton" value="Get Pics" onclick="parseURL()" />
<input type="button" id="back" value="<< Back" onclick="back()" disabled="true"/>
<input type="button" id="next" value="Next >>" onclick="next()" disabled="true"/>
</form>
</div>
</div>
</div>
</BODY>
</HTML>
It seems like it should be an easy fix, I've tried a bunch of things though and nothing seems to be working. Any help is appreciated.
Share Improve this question edited Oct 26, 2016 at 14:22 ps2goat 8,4951 gold badge39 silver badges73 bronze badges asked Jul 27, 2011 at 21:06 Andrew BortAndrew Bort 31 silver badge2 bronze badges3 Answers
Reset to default 2Move this:
<script type="text/javascript" src="linkedURL.js" />
to here:
<script type="text/javascript" src="linkedURL.js"> </script>
</BODY>
Do you actually have those hashes in your JavaScript? If so, they'll kill your script pletely.
If you want to ment in JavaScript, you can use single line ments:
// This is a ment.
or multi-line ments:
/* This is
a ment */
I can see a few problems in that js, one of which may be causing the error :
- You should not write , but always use . Some browsers are quite stupid.
- You call document.getElementById("link") right at the beginning of the script. When that line executes, there is no element in the document having id link ... there is no element in the document at all. A naive solution is to move all the scripts at the end of the page, while the formally correct solution is to use the onload event.
- Javascript does not support ments with #. It supports // for single lines, and /* .. */ for multiple lines.
本文标签: javascriptUncaught ReferenceError parseURL is not definedStack Overflow
版权声明:本文标题:javascript - Uncaught ReferenceError: parseURL is not defined - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745481660a2660199.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论