473,804 Members | 2,070 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

code embedded in html file vs .js file reference

at least i think it this is the problem
am trying to fix a webpage/javascript that i didn't write
www.deltaneutral.com when invoked or any new page from the menu, get the
error msg
line 2
char 1
syntax error
code 0
there is a java scipt file invoked early on that 'seems' to be the problem,
its just after the body tag
<script language=javasc ript src=/scripts/swap.js></script>
the code is at the end of this post
however, when i embed the code directly in the page, instead of the file
reference, the error goes away
and the functions seem to execute ok
i have checked the .js file with a hex editor looking for hidden weird bytes
but havent' found any
that look out of the ordinary, so i'm stumped why the seemingly same code
gets the error msg
only when it is invoked via its .js file
also i have loaded the html and .js file on a different, 2nd web server just
to be sure that somehow
the primary server isn't somehow supplying the .js file with a funny byte

<script type="text/javascript">
//alert ("now entering swap2ansi");
function WM_imageSwap(da Image, offOn){
var daPath = "images/";
var daPage = "home";
// Check to make sure that images are supported in the DOM.
if(document.ima ges){
// Check to see whether you are using a name, number, or object
if (typeof(daImage ) == 'string') {
// This whole objStr nonesense is here solely to gain compatability
// with ie3 for the mac.

objStr = 'document.' + daImage;
obj = eval(objStr);
srcStr = daPath + "nav_" + daImage + "_" + offOn + ".gif";
//srcEval = eval(daPath);
obj.src = srcStr;

objStr2 = 'document.' + daPage;
obj2 = eval(objStr2);

if (offOn == "on") {
srcStr2 = daPath + "nav_" + daPage + "_off.gif";
obj2.src = srcStr2;
} else {
srcStr2 = daPath + "nav_" + daPage + "_on.gif";
obj2.src = srcStr2;
}

} else if ((typeof(daImag e) == 'object') && daImage && daImage.src) {

daImage.src = daPath + "nav_" + daImage + "_" + offOn + ".gif";
if (offOn == "on") {
daPage.src = daPath + "nav_" + daPage + "_off.gif";
} else {
daPage.src = daPath + "nav_" + daPage + "_on.gif";
}
}
}
}
function SimpleSwap(daIm age, daSrc){
var objStr,obj;
//alert ("now entering simple swap");
// Check to make sure that images are supported in the DOM.
if(document.ima ges){
// Check to see whether you are using a name, number, or object
if (typeof(daImage ) == 'string') {
// This whole objStr nonesense is here solely to gain compatability
// with ie3 for the mac.
objStr = 'document.' + daImage;
obj = eval(objStr);
obj.src = daSrc;
} else if ((typeof(daImag e) == 'object') && daImage && daImage.src) {
daImage.src = daSrc;
}
}
}
//
</script>

Jul 20 '05 #1
4 4770
On Sun, 07 Mar 2004 08:05:27 GMT, comcast news <bx******@comca st.net>
wrote:
at least i think it this is the problem
am trying to fix a webpage/javascript that i didn't write
www.deltaneutral.com when invoked or any new page from the menu, get
the
error msg
line 2
char 1
syntax error
code 0
there is a java scipt file invoked early on that 'seems' to be the
problem,
its just after the body tag
<script language=javasc ript src=/scripts/swap.js></script>
the code is at the end of this post
however, when i embed the code directly in the page, instead of the file
reference, the error goes away
and the functions seem to execute ok
i have checked the .js file with a hex editor looking for hidden weird
bytes
but havent' found any
that look out of the ordinary, so i'm stumped why the seemingly same
code
gets the error msg
only when it is invoked via its .js file
also i have loaded the html and .js file on a different, 2nd web server
just
to be sure that somehow
the primary server isn't somehow supplying the .js file with a funny byte

<script type="text/javascript">
//alert ("now entering swap2ansi");
function WM_imageSwap(da Image, offOn){
var daPath = "images/";
var daPage = "home";
// Check to make sure that images are supported in the DOM.
if(document.ima ges){
// Check to see whether you are using a name, number, or object
if (typeof(daImage ) == 'string') {
// This whole objStr nonesense is here solely to gain
compatability
// with ie3 for the mac.

objStr = 'document.' + daImage;
obj = eval(objStr);
srcStr = daPath + "nav_" + daImage + "_" + offOn + ".gif";
//srcEval = eval(daPath);
obj.src = srcStr;

objStr2 = 'document.' + daPage;
obj2 = eval(objStr2);

if (offOn == "on") {
srcStr2 = daPath + "nav_" + daPage + "_off.gif";
obj2.src = srcStr2;
} else {
srcStr2 = daPath + "nav_" + daPage + "_on.gif";
obj2.src = srcStr2;
}

} else if ((typeof(daImag e) == 'object') && daImage && daImage.src)
{

daImage.src = daPath + "nav_" + daImage + "_" + offOn + ".gif";
if (offOn == "on") {
daPage.src = daPath + "nav_" + daPage + "_off.gif";
} else {
daPage.src = daPath + "nav_" + daPage + "_on.gif";
}
}
}
}
function SimpleSwap(daIm age, daSrc){
var objStr,obj;
//alert ("now entering simple swap");
// Check to make sure that images are supported in the DOM.
if(document.ima ges){
// Check to see whether you are using a name, number, or object
if (typeof(daImage ) == 'string') {
// This whole objStr nonesense is here solely to gain
compatability
// with ie3 for the mac.
objStr = 'document.' + daImage;
obj = eval(objStr);
obj.src = daSrc;
} else if ((typeof(daImag e) == 'object') && daImage && daImage.src)
{
daImage.src = daSrc;
}
}
}
//
</script>


--
Michael Winter
M.******@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #2
On Sun, 07 Mar 2004 08:05:27 GMT, comcast news <bx******@comca st.net>
wrote:

[snip]
its just after the body tag
<script language=javasc ript src=/scripts/swap.js></script>
If this is the exact tag pair, the problem is that the src attribute value
is not quoted. Quotes *must* be used when the value includes characters
that are not among this set:

- Letters
- Numbers
- Underscores (_)
- Periods (.)
- Hyphens (-)
- Colons (:)

Furthermore, the type attribute is required for the script element, and
the language attribute is deprecated. The above should read:

<script type="text/javascript" src="/scripts/swap.js"></script>

You could also place it in the HEAD element so that it is guaranteed to be
available to the document.

[snip]

The script below contains unnecessary eval() function calls. You should
modify the code with the alternatives that I show below (comments have
been stripped for clarity).
<script type="text/javascript">
function WM_imageSwap(da Image, offOn){
var daPath = "images/";
var daPage = "home";
if(document.ima ges){
if (typeof(daImage ) == 'string') {

objStr = 'document.' + daImage;
obj = eval(objStr);
daImage is a string that contains the name or id of an IMG element,
correct? If so, it should be accessed using the images collection:

obj = document.images[ daImage ];

For future reference, you could have avoided the eval() call using:

obj = document[ daImage ];

If daImage was 'logo', for example, it would be the same as writing:

obj = document.logo;
srcStr = daPath + "nav_" + daImage + "_" + offOn + ".gif";
//srcEval = eval(daPath);
Image.src expects a string, so that eval() should never have been
necessary. The assignment might as well be direct, too: the value isn't
used elsewhere, so the variable is unnecessary.

Both of intermediate variables (objStr and srcStr) have been declared
global unnecessarily. Use the var keyword to keep them local.
obj.src = srcStr;

objStr2 = 'document.' + daPage;
obj2 = eval(objStr2);
This should probably be:

obj2 = document.images[ daPage ];

and if not, it should certainly be:

obj2 = document[ daPage ];

[snipped object branch]
function SimpleSwap(daIm age, daSrc){
var objStr,obj;
if(document.ima ges){
if (typeof(daImage ) == 'string') {
objStr = 'document.' + daImage;
obj = eval(objStr);
I'm sure you can guess by now how this should be written.
obj.src = daSrc;
} else if ((typeof(daImag e) == 'object') && daImage && daImage.src)
{
daImage.src = daSrc;
}
}
}
//
Informative comment! :P
</script>


Hope that helps,
Mike

--
Michael Winter
M.******@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #3
comcast news wrote:
at least i think it this is the problem
am trying to fix a webpage/javascript that i didn't write
www.deltaneutral.com when invoked or any new page from the menu, get
the error msg


..js files should contain JavaScript, not a combination of HTML and
JavaScript.

Get rid of the <script> tags from .js files.

(and run the HTML through http://validator.w3.org/ )
--
David Dorward <http://dorward.me.uk/>
Jul 20 '05 #4
Michael Winter wrote: <op************ **@news-text.blueyonder .co.uk>
<snip>
<script type="text/javascript">
function WM_imageSwap(da Image, offOn){

<snip>

There are two other common causes of javascript moved to external files
not working in that location when they work form a page. The first is
including HTML in the external file, so if that opening script tag is in
the external file it becomes a syntax error because it is not
javascript. (SGML comment tags are also often syntax errors in external
JS files)

The other is badly configured servers, specifically older apache
versions where files with JS extensions are not associated with a known
content type so the server sends them as text/html (which doesn't matter
in itself) but also inserts an HTML 2.0 doctype, which is again a syntax
error in a javascript file. You don't see this second problem much these
days.

In both cases testing with Mozilla/Gecko browsers usually reveals the
problem as its error messages include the offending line of code, so it
is obvious when it is not javascript (or was not part of the original
file).

Richard.
Jul 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3558
by: Aquarius2431 | last post by:
Hi!, I don't think I have posted to this group before. Have been using PHP on my webserver for a few months now and finding that I like it quite a bit. Here is a question that just occurred to me. I recently created a BBS (Bulletin Board Service) on my website where I allow people to post messages via a form. It just occurred to me that conceivably they could embed php code in their message trying to 'hack' my site. So I
242
13473
by: James Cameron | last post by:
Hi I'm developing a program and the client is worried about future reuse of the code. Say 5, 10, 15 years down the road. This will be a major factor in selecting the development language. Any comments on past experience, research articles, comments on the matter would be much appreciated. I suspect something like C would be the best based on comments I received from the VB news group. Thanks for the help in advance James Cameron
16
2065
by: graham.reeds | last post by:
I am updating a website that uses a countdown script embedded on the page. When the page is served the var's are set to how long the countdown has left in minutes and seconds, but the rest of the script is left untouched. However I want to take the script out of the page and have it as a seperate file that can be cached, reducing serving costs - the page gets hit a couple of thousand times per day, sometimes as high a 5K, so any...
171
7826
by: tshad | last post by:
I am just trying to decide whether to split my code and uses code behind. I did it with one of my pages and found it was quite a bit of trouble. I know that most people (and books and articles) like it because you can split the code from the design. That is logical. But if you are the only one working on the code, it seem a little overkill. I use Dreamweaver to do my design and find it a bit of a hassle to have multiple files open...
2
4994
by: SAL | last post by:
I would like to create a VB.net function, that builds a dynamic hyperlink using System.Web.UI.WebControls.HyperLink, but I can not find any examples on how to generate a dynamic hyperlink. Has anyone done this before? I do not want to dynamically create my hyperlink on an ASP page, but rather a behind the scenes link that a user can paste into a Word document or Email, as an embedded link that points to a particular file. This would be...
0
5129
by: wulongtea | last post by:
I am trying generate an HTML email message with C# Visual Studio 2003 that has a graphics file embedded in the message. (I know i should be using 2005 and the new classes there, but I cannot upgrade yet due to the policy at my company) my function seems pretty simple. but what i get is an HTML email that has an attached file, whic his the graphics file. But I would like to have the graphics image embedded inside the email, so it displays with...
24
1539
by: Skijor | last post by:
I have inherited a php script that nests php, javascript, and html. How do I clean up code like this: I think I can move the javascript into a seperate .js file at the least. What about the nesting of php inside the html? <?php ....snip... function ShowCart()
1
2122
by: Peter Rilling | last post by:
Hi. I have an interesting problem and don't know if there is a solution to this. I have some webcontrols that are compiled into assemblies (not usercontrols). Some of these controls rely on Javascript file which are included as embedded resources where the HTML reference is being echoed by using the Page.ClientScript.GetWebResourceUrl(...). This works fine. Now I have an HTC that I want to include as an embedded resource and
0
1837
by: Formula | last post by:
Hello everybody,because I am newbie in python two weeks only but I had programming in another languages but the python take my heart there's 3 kind of arrays Wow now I hate JAVA :) . I am working now on html process. So, I found a good class for getting html tag but I don't know how to use it I wrote this code for getting the tag A hopping some help please >>> <% import urllib from sgmllib import SGMLParser
0
9711
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10343
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10088
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9169
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7633
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6862
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4306
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3831
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.