PDA

View Full Version : inserting a body script on an external link



lordjeremiahs
11-22-2007, 12:18 PM
uhh.. i've got a problem. I want to use the scripts for my friendster profile. but, the site only accepts external javascript links (e.g.: <script src = "java.js"></script).

Heres the problem. I've tried a few times but it seems that only scripts for the <head> tag work! (e.g.: this script: http://www.dynamicdrive.com/dynamicindex8/automax.htm). but when it comes to scripts that need something to insert in the <body> tag, it screws up! (e.g.:http://dynamicdrive.com/dynamicindex4/spotlight.htm).

i need explanations and solutions please. I'm a noob at javascript but experienced in visual basic and pascal.

jscheuer1
11-22-2007, 04:05 PM
Basically, the script tag needs to go in the spot that the internal script would have been. Here's a lot more info:

Use a text editor to save the script, call it 'file_name.js' where 'file_name' can be any valid file name of your choosing. Substitute the name of your external .js file for some.js in the below:


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

Common problems arise when:

1 ) The script file is not in the directory specified. In the above example it must be in the same directory as the page(s) that use it. Below, it can be in the scripts directory off of the root of a domain:


<script src="http://www.somedomain.com/scripts/some.js" type="text/javascript"></script>

2 ) Opening, closing and/or 'hiding' tags are left in the external file. This means that you must strip:
<script>
<!--and
//-->
</script>and any of their many variations from the beginning and end of the external file.

3 ) The external call (<script src="some.js" type="text/javascript"></script>) is not inserted into the page at the correct spot. The external call must be inserted at the same place on the page where the script was/would have been.

4 ) Paths to other files (if) used by the script are no longer valid due to its location. This is only a problem if the external script is kept in a different directory than the page it was working on when it was an internal script. To correct this, use absolute paths inside the script. Absolute path examples:


http://www.somedomain.com/images/button.gif

http://www.somedomain.com/~mysitename/index.html

5 ) Inappropriately combining two or more scripts into one external file. Usually external scripts can be combined if one knows enough about scripting to do so properly. Even then it is possible to overlook something.

A rule of thumb when testing is, if it won't work on the page, it won't work as an external file either.

One other thing, if this is a DD script or any script that requires the credit remain for legal use, include the credit in the on page call, ex:


<script src="some.js" type="text/javascript">
/***********************************************
* IFrame SSI script II- Dynamic Drive DHTML code library (http://www.dynamicdrive.com)
* Visit DynamicDrive.com for hundreds of original DHTML scripts
* This notice must stay intact for legal use
***********************************************/
</script>

Make sure to retain all the 'decorations', as these include begin and end javascript comment delimiters, without which the script won't function.

There is also info here:

http://www.javascriptkit.com/javatutors/external.shtml

lordjeremiahs
11-23-2007, 10:23 AM
seems like you don't understand my problem.. im not having problems with the syntax.. the <script src> thing.. it's just that.. all the codes that are supposed to be on the <head> tag are working, but the <body> codes arent! and note.. i've checked all the spellings ang syntax. and im sure the problem isnt because of that. try it the image spotlight for yourself using an external link. you'll see.

what i'm trying to say is that only the codes instructed to put in the <head> part work! so i am having limitations because i can't use codes that instructs to put something in the <body> part.
Edit:
3 ) The external call (<script src="some.js" type="text/javascript"></script>) is not inserted into the page at the correct spot. The external call must be inserted at the same place on the page where the script was/would have been.

-- this, uhmm.. its just that, the method of inserting scripts are limited. I don't know if the script is directed to the <head> part or any other else. But, if it is on the <head> part, is there a way to put it in the <body> part?

jscheuer1
11-23-2007, 04:43 PM
Just about any script that goes in the body can be made to work from the head, and the other way around. But modification of the code is often required. For instance, in the example that you gave (which is a bit of a special case because it is an IE only script), of the spotlight script, this (red, key parts also background highlighted) could go in the head:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<!--[if gte IE 5.5]>
<link rel="stylesheet" href="spot.css" type="text/css">
<script type="text/javascript" src="spot.js" defer>
//Image spotlight effect- By Erik F (die_schlampe@hotmail.com)
//Code enhancements by Dynamicdrive.com
//Visit http://www.dynamicdrive.com for this script
</script>
<![endif]-->
</head>
<body>
<img id="myimage" src="theimage.jpg">
</body>
</html>

The if/endif makes sure that only filter capable versions of IE even try this, and the defer attribute is an IE only way of making sure that the browser parses the body before running the script (in others it only means that browser may wait). The defer bit in IE is almost too easy, with scripts that include other browsers, and that need to go in the body after some bit of HTML markup, generally some kind of onload event would need to be added to the script code itself.

Notice that the image tag, which all along was ordinary HTML, still needs to go in the body. But, that could be dealt with in another way too.

OK, here is (unmodified except for removing the style and comment tags) spot.css:


#myimage {
filter:light
}

and spot.js, all I did was remove the script tags:


//Image spotlight effect- By Erik F (die_schlampe@hotmail.com)
//Code enhancements by Dynamicdrive.com
//Visit http://www.dynamicdrive.com for this script

s = 50; // the size of the spotlight
vp = 10; // the visibility percent of the picture
startx = 0; // the top position of your sportlight into the image (on start)
starty = 0; // the left position of your spotlight into the image (on start)


//////////////////////////////////////////////////////////////////
// No need to edit below this line //
//////////////////////////////////////////////////////////////////

var IE = document.all?true:false

function moveL()
{
xv = tempX;
yv = tempY;
myimage.filters.light.MoveLight(1,xv,yv,s,true);
}

if (IE&&myimage.filters)
document.all.myimage.onmousemove = getMouseXY;
var tempX = 0
var tempY = 0


function getMouseXY(e) {
tempX = event.offsetX
tempY = event.offsetY

if (tempX < 0){tempX = 0}
if (tempY < 0){tempY = 0}
if (t)
{
moveL();
}

return true
}

var xv = startx;
var yv = starty;
var t= true;
if (IE&&myimage.filters){
myimage.style.cursor="hand";
myimage.filters.light.addAmbient(255,255,255,vp)
myimage.filters.light.addPoint(startx,starty,s,255,255,255,255)
}

But, using the same external files, and being able to mark the page up as desired (to duplicate where the code would have been with the external calls that bring it), one could do this and let the script itself worry about which browser is being used, and that requires no modification of the script or style code other than removing their tags (just like with a head script):


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" href="spot.css" type="text/css">
</head>
<body>
<img id="myimage" src="theimage.jpg">
<script type="text/javascript" src="spot.js">
//Image spotlight effect- By Erik F (die_schlampe@hotmail.com)
//Code enhancements by Dynamicdrive.com
//Visit http://www.dynamicdrive.com for this script
</script>
</body>
</html>

Note: This script, as do many others, also includes a stylesheet. That could have remained on the page in the head, but style (regardless of whether it is used by a script or not) may always be made external using the link tag.

lordjeremiahs
11-23-2007, 11:24 PM
ohh.. thats what i'm looking for. but it's ALMOST mission complete because i still have one problem.

I was given this script format insert javascript in my friendster page:

<img width=0 height=0 id=ArchAngell src=''/onError ="a=document.createElement('script');a.src='http://www.geocities.com/angell.deville/loaders/getExternal.swf';navBg.appendChild(a)" alt="hello"><div id='loader' class='Linker credits to ArchAngell' style='visibility:hidden;'>http://h1.ripway.com/lordjeremiahs/crossoverdarker/darkroom.js</div>

how can i put a defer tag here?!

lordjeremiahs
11-24-2007, 03:38 AM
bump..!

jscheuer1
11-24-2007, 05:49 AM
I know nothing about coding for friendster, and that code (though I can sort of follow it) looks like garbage to me. I know that it may well be what is required to work (around) on friendster, it just doesn't conform to anything that I recognise as standard or advisable to begin with. It certainly looks like a way to get something done that perhaps might not be otherwise allowed.

Due to my unfamiliarity with what friendster does or doesn't allow on its pages, I'm afraid (due to the forum rules here that don't allow us to aid in contravening a host contract) that I cannot be of much help here.

Perhaps you should start a thread about it in a 'coding for friendster' forum (if there are any).