Log in

View Full Version : Need help with javascript code displaying at top of wepage



baldrn
02-17-2013, 02:37 PM
Hi,
Bottom line is I have a website TEMPLATE that is displaying, code text, at the top of a webpage and then at the bottom the webpage displays correctly and functions as it should. I have restored a functioning website from a previously made backup from the host. So, showing you live would do no good as it appears ok now. Problem is that I need that template itself corrected.(Which wasn't backed up at the host and apparantly my Carbonite backup was corrupted as well.) Problem that the top of the template page is displaying live view such as this:

function(element, className) { return $A($(element).childNodes).collect( function(node) { return (node.nodeType==3 ? node.nodeValue : ((node.hasChildNodes() && !Element.hasClassName(node,className)) ? Element.collectTextNodes(node) : '')); }).flatten().join(''); } Element.setStyle = function(element, style) { element = $(element); for(k in style) element.style[k.camelize()] = style[k]; } Element.setContentZoom = function(element, percent) { Element.setStyle(element, {fontSize: (percent/100) + 'em'}); if(navigator.appVersion.indexOf('AppleWebKit')>0) window.scrollBy(0,0); } Element.getOpacity = function(element){ var opacity; if (opacity = Element.getStyle(element, 'opacity')) return parseFloat(opacity); if (opacity = (Element.getStyle(element, 'filter') || '').match(/alpha\(opacity=(.*)\)/)) if(opacity[1]) return parseFloat(opacity[1]) / 100; return 1.0; } Element.setOpacity = function(element, value){ element= $(element); if (value == 1){ Element.setStyle(element, { opacity: (/Gecko/.test(navigator.userAgent) &&
That's just a small part of it.
History: It previously was working perfectly. I used Lightbox JS from here and Dreamweaver to design and publish the site. I haven't touched this code for over a year, that I remember. A few days ago I needed to update it. I went back in and opened the local template to update a date, updated all of the pages then uploaded those. That is when the error became obvious.
I know it's something as simple as a bracket that has been deleted or something but for the life of me I cannot figure out what to do. I don't write code. I can work with copy and so forth.
I was wondering if there is something just clearly obvious in code, that I could locate myself, that might be causing this to display?
Many thanks,
Mark

Beverleyh
02-17-2013, 04:13 PM
I think for this you'll need to brave the code view and provide that for us to make any concrete suggestions.

If you're seeing code fragments above the pretty stuff in WYSIWYG view, I'd say that its because the JavaScript opening/closing tags are missing, so Dreamweaver is interpreting the rest of the code (the stuff that should be inside the script tags) as plain text and therefore making it visible as such is the template/design. I'm not 100% sure but that seems like a fair place to start.

jscheuer1
02-17-2013, 04:58 PM
If the page below all that code displays correctly and functions as it should. You can just delete that code from the template. Keep a backup in case you delete the wrong code.

baldrn
02-18-2013, 12:22 AM
I tried to post it all here, but it's too much for all of the code.
I did delete the code like the mod said, and it did disappear. However, the lightbox effects also disappeared. So, I had to replace it.
But,
Here is the top of the code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

// Copyright (c) 2005 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
// Contributors:
// Justin Palmer (http://encytemedia.com/)
// Mark Pilgrim (http://diveintomark.org/)
// Martin Bialasinki
//
// See scriptaculous.js for full license.

/* ------------- element ext -------------- */

// converts rgb() and #xxx to #xxxxxx format,
// returns self (or first argument) if not convertable
String.prototype.parseColor = function() {
var color = '#';
if(this.slice(0,4) == 'rgb(') {
var cols = this.slice(4,this.length-1).split(',');
var i=0; do { color += parseInt(cols[i]).toColorPart() } while (++i<3);
} else {
if(this.slice(0,1) == '#') {
if(this.length==4) for(var i=1;i<4;i++) color += (this.charAt(i) + this.charAt(i)).toLowerCase();
if(this.length==7) color = this.toLowerCase();
}
}
return(color.length==7 ? color : (arguments[0] || this));
}


And here is a clip from the bottom into the body. *the rest appears to me to be just javascript commands.

Effect.Fold = function(element) {
element = $(element);
var oldStyle = {
top: element.style.top,
left: element.style.left,
width: element.style.width,
height: element.style.height };
Element.makeClipping(element);
return new Effect.Scale(element, 5, Object.extend({
scaleContent: false,
scaleX: false,
afterFinishInternal: function(effect) {
new Effect.Scale(element, 1, {
scaleContent: false,
scaleY: false,
afterFinishInternal: function(effect) { with(Element) {
[hide, undoClipping].call(effect.element);
setStyle(effect.element, oldStyle);
}} });
}}, arguments[1] || {}));
}



<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- TemplateBeginEditable name="doctitle" -->
<title>Untitled Document</title>
<!-- TemplateEndEditable -->
<link href="../twoColElsLtHdr.css" rel="stylesheet" type="text/css" />
<!--[if IE]>
<style type="text/css">
/* place css fixes for all versions of IE in this conditional comment */
.twoColElsLtHdr #sidebar1 { padding-top: 30px; }
.twoColElsLtHdr #mainContent { zoom: 1; padding-top: 15px; }
/* the above proprietary zoom property gives IE the hasLayout it needs to avoid several bugs */
</style>
<![endif]-->
<style type="text/css">
<!--
a:link {
color: #000000;
text-decoration: none;
}
a:visited {
text-decoration: none;
color: #000000;
}
a:hover {
text-decoration: none;
color: #3EAC33;
}
a:active {
text-decoration: none;
color: #F8804C;
}
-->
</style>
<script type="text/javascript" src="js/prototype.js"></script>
<script type="text/javascript" src="js/scriptaculous.js?load=effects"></script>
<script type="text/javascript" src="js/lightbox.js"></script>
<link rel="stylesheet" href="css/lightbox.css" type="text/css" media="screen" />
<!-- TemplateBeginEditable name="head" --><!-- TemplateEndEditable -->
</head>

<body class="twoColElsLtHdr">

<div id="container">
<div id="header">
<h1>&nbsp;</h1>
<!-- end #header --></div>
<div id="sidebar1">
<h3>&nbsp;</h3>
<table width="185" align="center">

Now, I found this was not in there (remember this is the template), so I pasted it from a WORKING page that I downloaded. I just need the temp back working again so I can update pages without them breaking.

<script type="text/javascript" src="js/prototype.js"></script>
<script type="text/javascript" src="js/scriptaculous.js?load=effects"></script>
<script type="text/javascript" src="js/lightbox.js"></script>
<link rel="stylesheet" href="css/lightbox.css" type="text/css" media="screen" />
I dunno. :?
lol
I'm trying here! I only do this as a hobby, more or less, for small businesses.
Thanks for the help from the above posters and moderators! This is a great forum.
Mark
NOTE TO SELF..back up templates too. :)

jscheuer1
02-18-2013, 04:34 AM
Any javascript code that isn't between <script> and </script> tags should be removed.

You can pretty much see. Any javascript code that shows as text on the page isn't in script tags, so you can search the file for that and remove it.

That said, an experienced eye might have a better chance. You can attach your file. Save a copy of it as a .txt file. If you don't see the little attachment icon:

4942

along with the other icons at the top of the editor here, hit the "Go Advanced" button at the bottom of the editor. Then hit the attachment icon and use the window that pops up to attach your file to your post.

baldrn
02-18-2013, 09:38 PM
It's FIXED!
Ok, here is what I think happened. all of that extra code??? I don't know wth it came from, but it was there. I don't even know what it was connected to.
Because I went back to the original DD lightbox, http://www.dynamicdrive.com/dynamicindex4/lightbox2/index.htm, and reviewed it.(should have done in the first place!!)
And, in the head there is NOTHING except:


<script type="text/javascript" src="js/prototype.js"></script>
<script type="text/javascript" src="js/scriptaculous.js?load=effects"></script>
<script type="text/javascript" src="js/lightbox.js"></script>
<link rel="stylesheet" href="css/lightbox.css" type="text/css" media="screen" />

So, I took the red pill, backed all of the Matrix out, put that code above back in and voila..it works again like it used to.
I'm glad. I hate to have stuff I can't figure out.
But to this day, I CANNOT figure out where all of that script stuff came from:


// Copyright (c) 2005 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
// Contributors:
// Justin Palmer (http://encytemedia.com/)
// Mark Pilgrim (http://diveintomark.org/)
// Martin Bialasinki//
// See scriptaculous.js for full license.

I guess at this point, that's fine to just never know.
Thanks for this site and the help!
Mark

jscheuer1
02-18-2013, 09:51 PM
That's the content of the effects.js script file. Some kind of file corruption may be to blame. You should check your hard disk's integrity.

But it might have been the result of copying from some kind of Developer Tools application.

baldrn
02-19-2013, 02:50 AM
You should check your hard disk's integrity.


Yea, I run a check on it occasionally with TuneUp Utilities.
I may never know.

jscheuer1
02-19-2013, 05:23 AM
Another thought occurred to me. There are PHP and other server side hacks that will take code from one file and place it along with something malicious in another file. What happens in this sort of attack is that a hacker gains enough access to the server to upload a file that does this rewriting. If after that happened you downloaded the file over your copy, that could explain it. Except in this case the hacker must have messed up somehow, because the added code isn't supposed to be visible on the live page, only in its source view.

I'm not sure how you can find out if this is what happened, there are ways though. If it happens again and you can tell that it came from the server, you can ask about it in the:

http://www.dynamicdrive.com/forums/forumdisplay.php?12-Other

forum. Some folks there will probably be able to help you.

It's also possible that there was simple file corruption on the server and that you then downloaded a copy of the corrupted file over your local one.

baldrn
02-19-2013, 08:32 PM
Good thought. But the server files all displayed correctly. Actually, that was my only saving moment.
I had made a backup of all my addon domains ON THE SERVER in January.
So, once I uploaded the updated files from my local pc, it overwrote the good files.
I was able to get Hostgator to restore that addon back to the January files. But..the correct template wasn't backed up. I keep those local and only upload the necessary files.
Thanks for thinking of that and I had heard of that possibility.
But, again, I don't think the server files were harmed or the January html files backup wouldn't have worked.
Mark