/    Sign up×
Community /Pin to ProfileBookmark

javascriptsource.com script not working

I’m trying to use a script listed at [url]http://javascript.internet.com/bgeffects/background-changer.html[/url]
and its not working….

I changed the images and heres what it looks like now:

[CODE]

<html>

<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=windows-1252″>
<title>backgrounds</title>

<SCRIPT LANGUAGE=”JavaScript”>

<!– Begin
if (navigator.appName == “Microsoft Internet Explorer”)
{
image_directory = “http://www.baptistrevival.com/baptistkitty/graphics/backgrounds/”;
clear = new Image(); clear.src = image_directory + “clear.jpg”;
pic1 = new Image(); pic1.src = image_directory + “blue.jpg”;
pic2 = new Image(); pic2.src = image_directory + “fur.jpg”;
pic3 = new Image(); pic3.src = image_directory + “fuzzy.jpg”;
pic4 = new Image(); pic4.src = image_directory + “greychecks.jpg”;
}
function imagechange(imgName)
{
if (navigator.appName == “Microsoft Internet Explorer”)
{
document.body.background = eval(imgName + “.src”);
}
}
// End –>
</script>

</head>

<body background=”clear.jpg” name=bg>

<a href=”#” onMouseOver=”imagechange(‘pic1’);” onMouseOut=”imagechange(‘clear’);”><img src=”blue.jpg”></a>
<a href=”#” onMouseOver=”imagechange(‘pic2’);” onMouseOut=”imagechange(‘clear’);”><img src=”fur.jpg”></a>
<a href=”#” onMouseOver=”imagechange(‘pic3’);” onMouseOut=”imagechange(‘clear’);”><img src=”fuzzy.jpg”></a>
<a href=”#” onMouseOver=”imagechange(‘pic4’);” onMouseOut=”imagechange(‘clear’);”><img src=”greychecks.jpg”></a>

</body>

</html>

[/CODE]

I know I have the right path to the image but it wont work in the script…

Am I doing something wrong? ?

Thanks…

Trina

to post a comment
JavaScript

23 Comments(s)

Copy linkTweet thisAlerts:
@KravvitzOct 18.2005 — if (navigator.appName == "Microsoft Internet Explorer")
Why?!?

Edit: Oh, I see. You just copied a badly written script.
Copy linkTweet thisAlerts:
@BaptistKittyauthorOct 18.2005 — ummm.... any advice for me then???
Copy linkTweet thisAlerts:
@KravvitzOct 18.2005 — Be very careful about what ready-made scripts you use. There are very many badly written scripts available on the web.

Here's what you want.
&lt;script [b]type="text/javascript"[/b]&gt;&lt;!--

[b]if(document.images)[/b]
{
var image_directory = "http://www.baptistrevival.com/baptistkitty/graphics/backgrounds/";
var clear = new Image(); clear.src = image_directory + "clear.jpg";
var pic1 = new Image(); pic1.src = image_directory + "blue.jpg";
var pic2 = new Image(); pic2.src = image_directory + "fur.jpg";
var pic3 = new Image(); pic3.src = image_directory + "fuzzy.jpg";
var pic4 = new Image(); pic4.src = image_directory + "greychecks.jpg";
}
function imagechange(imgName)
{
[b]if(document.images &amp;&amp; document.body &amp;&amp; document.body.style)[/b]
{
[b]document.body.style.backgroundImage = "url("+window[imgName].src+")";[/b]
}
}
// --&gt;
&lt;/script&gt;
&lt;/head&gt;
&lt;body [b]style="background-image: url(clear.jpg)"[/b]&gt;
Copy linkTweet thisAlerts:
@BaptistKittyauthorOct 18.2005 — heh heh.. boy do I feel stupid.... did you know that if a picture is a .gif and you put it in as a .jpg it doesnt work..... wow....

anyways the mouse over part of it doesnt work.... and there is an error saying 'window[...].src' is null or not an object

also, does you changing what you changed mean its no longer just an IE script?

thanks again
Copy linkTweet thisAlerts:
@KravvitzOct 18.2005 — did you know that if a picture is a .gif and you put it in as a .jpg it doesnt work..... wow.... [/QUOTE]
Yes, I've known that for years. The extension (.gif, .jpg, etc.) is part of the filename.

anyways the mouse over part of it doesnt work.... and there is an error saying 'window[...].src' is null or not an object[/QUOTE]
Sounds like the function is trying to access a variable that doesn't exist. Did you change any of the code?

also, does you changing what you changed mean its no longer just an IE script?

thanks again[/QUOTE]

It works in IE4+, Firefox, Netscape 6.2+, and Opera 7+.

You're welcome ?
Copy linkTweet thisAlerts:
@konithomimoOct 18.2005 — You have:
<i>
</i>document.body.style.backgroundImage = "url("+window[imgName].src+")";


.src is for iframes, which you are not using. You have to use "location.href"

<i>
</i>document.body.style.backgroundImage = "url("+window[imgName].location.href+")";
Copy linkTweet thisAlerts:
@KravvitzOct 18.2005 — konithomimo, look at the script again. Those are images, which do have a src attribute.

BaptistKitty, don't pay any attention to konithomimo's post.
Copy linkTweet thisAlerts:
@BaptistKittyauthorOct 19.2005 — yeah, I was trying to be sarcastic about the image extention thing....

I didn't change the script... it still looks like this:

[CODE]
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>backgrounds</title>

<script type="text/javascript"><!--

if(document.images && document.body && document.body.style)
{
var image_directory = "http://www.baptistrevival.com/baptistkitty/graphics/backgrounds/";
var clear = new Image(); clear.src = image_directory + "clear.jpg";
var pic1 = new Image(); pic1.src = image_directory + "blue.jpg";
var pic2 = new Image(); pic2.src = image_directory + "fur.gif";
var pic3 = new Image(); pic3.src = image_directory + "fuzzy.gif";
var pic4 = new Image(); pic4.src = image_directory + "greychecks.gif";
}
function imagechange(imgName)
{
if(document.images && document.body && document.body.style)
{
document.body.style.backgroundImage = "url("+window[imgName].src+")";
}
}
// -->
</script>
</head>
<body style="background-image: url(clear.jpg)">

<a href="#" onMouseOver="imagechange('pic1');" onMouseOut="imagechange('clear');"><img src="blue.jpg"></a>
<a href="#" onMouseOver="imagechange('pic2');" onMouseOut="imagechange('clear');"><img src="fur.gif"></a>
<a href="#" onMouseOver="imagechange('pic3');" onMouseOut="imagechange('clear');"><img src="fuzzy.gif"></a>
<a href="#" onMouseOver="imagechange('pic4');" onMouseOut="imagechange('clear');"><img src="greychecks.gif"></a>


</body>

</html>

[/CODE]


when you put your mouse over the picture its suppost to make that picture the background.... and thats the part thats not working...

sorry to bug you like this but I don't understand why its not working.... :o

again... thanks
Copy linkTweet thisAlerts:
@FangOct 19.2005 — The [I]if[/I] statement is wrong; there is no body until the document has loaded.

Change to:
if(document.images)
{
.
.
Copy linkTweet thisAlerts:
@konithomimoOct 19.2005 — What Fang is trying to say is that you have:

<i>
</i>if(document.images &amp;&amp; [b]document.body &amp;&amp; document.body.style[/b])
{

The bold parts arent valid because the body hasnt been created when that if-statement is checked.

You have to either change that to:
<i>
</i>if(document.images)
{


or put in in a function and call it from the body onload. (that is pointless though)
Copy linkTweet thisAlerts:
@BaptistKittyauthorOct 19.2005 — ummm ok, that doesnt fix it and right after it is this....

{

document.body.style.backgroundImage = "url("+window[imgName].src+")";

}

so wouldn't it mess that up?
Copy linkTweet thisAlerts:
@FangOct 19.2005 — The script will work, unless there is something wrong with the image path.
Copy linkTweet thisAlerts:
@konithomimoOct 19.2005 — ummm ok, that doesnt fix it and right after it is this....

{

document.body.style.backgroundImage = "url("+window[imgName].src+")";

}

so wouldn't it mess that up?[/QUOTE]


That line is in a function that is run after the body has loaded when you call it via the line:
<i>
</i>&lt;a href="#" [b]onMouseOver="imagechange('pic1');" [/b]onMouseOut="imagechange('clear');"&gt;&lt;img src="blue.jpg"&gt;&lt;/a&gt;


The bold text is your first call to the function which contains the line you are asking about.
Copy linkTweet thisAlerts:
@konithomimoOct 19.2005 — It would be helpful if we could tell if the images were actually there, but the links you give always time out and cause the action to be cancelled.
Copy linkTweet thisAlerts:
@BaptistKittyauthorOct 19.2005 — I don't understand what your getting at.... I know very little about JS and what you all are saying isn't making any sense... it seems to me like you all are not finishing your sentences and I have no clue what's going on.... All I know is I have what I showed you and it doesnt work... the original page I got it from worked but when I coppied and pasted and changed it to where my pictures are... It didnt work.... I asked for help and made the changes that were suggested but it still doesn't... I'm sorry If am sounding rude or kinda dippy or whatever but I'm just getting fustrated because I don't understand.

thanks
Copy linkTweet thisAlerts:
@FangOct 19.2005 — I tested the script with my own images, it does work.

The images/paths appear to be at fault.
Copy linkTweet thisAlerts:
@konithomimoOct 19.2005 — All that does for me is time out, causing the page to not load. That might be why your function isnt working. If it takes too long to bring up the picture then it will cancel the function and nothing will happen.

Either that or you do not have your server set up for public viewing.
Copy linkTweet thisAlerts:
@BaptistKittyauthorOct 19.2005 — hmmm... no it works on my comp and my dads comp....

try it like this and tell me if it works for you...

http://baptistrevival.com:8081/baptistkitty/graphics/backgrounds/blue.jpg
Copy linkTweet thisAlerts:
@konithomimoOct 19.2005 — No, because that is the URL that all of your links try to load.

The page cannot be displayed

The page you are looking for is currently unavailable. The Web site might be experiencing technical difficulties, or you may need to adjust your browser settings.


--------------------------------------------------------------------------------

Please try the following:

Click the Refresh button, or try again later.

If you typed the page address in the Address bar, make sure that it is spelled correctly.

To check your connection settings, click the Tools menu, and then click Internet Options. On the Connections tab, click Settings. The settings should match those provided by your local area network (LAN) administrator or Internet service provider (ISP).

If your Network Administrator has enabled it, Microsoft Windows can examine your network and automatically discover network connection settings.

If you would like Windows to try and discover them,

click Detect Network Settings

Some sites require 128-bit connection security. Click the Help menu and then click About Internet Explorer to determine what strength security you have installed.

If you are trying to reach a secure site, make sure your Security settings can support it. Click the Tools menu, and then click Internet Options. On the Advanced tab, scroll to the Security section and check settings for SSL 2.0, SSL 3.0, TLS 1.0, PCT 1.0.

Click the Back button to try another link.



Cannot find server or DNS Error

Internet Explorer

[/QUOTE]


That is what I get.

The script does work though because I have tried it. The problem has to be your image path, or that you dont have you directory open to the public.
Copy linkTweet thisAlerts:
@BaptistKittyauthorOct 19.2005 — ok... I just got another script... Its not the exact same but it works. try it out and tell me if it works for you

http://www.baptistrevival.com/baptistkitty/graphics/backgrounds/
Copy linkTweet thisAlerts:
@KravvitzOct 21.2005 — Sorry about the confusion. BaptistKitty copied the script that I posted before I realized that the first if() was wrong and went back to fix it.

It seems that BaptistKitty's server is preventing hotlinking to the images, because I can access them directly, but they won't load when I test the script with them.

The script does work when I use local images.
×

Success!

Help @BaptistKitty spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...