1
Paxination
javascript issues
  • 2006/12/17 23:55

  • Paxination

  • Just popping in

  • Posts: 24

  • Since: 2006/12/7


I am trying to get the background to change on every click of a link. It works fine on a normal html website. But it wont work in xoops. I have the javascript file in the include folder with the images directory in it. And I have the file linked to in the theme.html file. I check the error console in firefox and there are no errors. Just no change. Here is my javascript code.

var backgroundpics = new Array();
backgroundpics[0] = "images/background1.jpg";
backgroundpics[1] = "images/background2.jpg";
backgroundpics[2] = "images/background3.jpg";
backgroundpics[3] = "images/background4.jpg";
backgroundpics[4] = "images/background5.jpg";

function 
changebackground()
{
var 
number = (Math.floor(Math.random()*5))
document.body.background=backgroundpics[number]
}


the function is access as an onclick event in the usermenu and mainmenu templates which i have edited.

2
Paxination
Re: javascript issues
  • 2006/12/18 1:32

  • Paxination

  • Just popping in

  • Posts: 24

  • Since: 2006/12/7


Ok maybe if I rephrase my question I might get some help. Will there be any issues using javascript to access certain html objects and modify them? Like with my background there. All I am doing is changing the background img in the body tag. Just not sure it will work since its php generated html.

3
Bassman
Re: javascript issues
  • 2006/12/18 1:38

  • Bassman

  • Friend of XOOPS

  • Posts: 1272

  • Since: 2003/5/23


Are you calling the javascript with a direct url? You need something like
Quote:




if in the site's root
or

Quote:




if in the theme (you are using) folder.

Same thing applies with the images.

4
Paxination
Re: javascript issues
  • 2006/12/18 1:44

  • Paxination

  • Just popping in

  • Posts: 24

  • Since: 2006/12/7


I didnt use the LINK tag...i used the script tag. I know the javascript is loading because I dont see the changebackground() not defined in error anymore. I tried a direct url and a fold path with the images. The javascript and images folder are in the include folder. So how should the path to the images be in the javascript? url or fold path?

5
Bassman
Re: javascript issues
  • 2006/12/18 1:59

  • Bassman

  • Friend of XOOPS

  • Posts: 1272

  • Since: 2003/5/23


Quote:




etc

6
Paxination
Re: javascript issues
  • 2006/12/18 2:22

  • Paxination

  • Just popping in

  • Posts: 24

  • Since: 2006/12/7


I cant use html tags in the javascript. Or can I? And I dont think XOOPS variables will work in the javascript either will it? Since javascript is browser side so I dont think the php parser would see it am I right?

7
Bassman
Re: javascript issues
  • 2006/12/18 2:33

  • Bassman

  • Friend of XOOPS

  • Posts: 1272

  • Since: 2003/5/23


Why not put your images into a folder in your theme and try
Quote:

var backgroundpics = new Array();
backgroundpics[0] = "<{$xoops_imageurl}>/images/background1.jpg";
backgroundpics[1] = "<{$xoops_imageurl}>/images/background2.jpg";
backgroundpics[2] = "<{$xoops_imageurl}>/images/background3.jpg";
backgroundpics[3] = "<{$xoops_imageurl}>/images/background4.jpg";
backgroundpics[4] = "<{$xoops_imageurl}>/images/background5.jpg";

function changebackground()
{
var number = (Math.floor(Math.random()*5))
document.body.background=backgroundpics[number]
}


Or try the random php script at http://alistapart.com/articles/randomizer/

8
Paxination
Re: javascript issues
  • 2006/12/18 2:59

  • Paxination

  • Just popping in

  • Posts: 24

  • Since: 2006/12/7


I tried that method and it didnt work. And that php script aint going to work since the background img is called from the css file (trying to keep at html standard).

9
Bassman
Re: javascript issues
  • 2006/12/18 3:12

  • Bassman

  • Friend of XOOPS

  • Posts: 1272

  • Since: 2003/5/23


actually, the PHP script will work. I've done it before.

10
Paxination
Re: javascript issues
  • 2006/12/18 3:17

  • Paxination

  • Just popping in

  • Posts: 24

  • Since: 2006/12/7


I tried it. It dont for me. You got it to work from a css file? like this....

body {colorblackbackgroundwhitemargin0padding0background-image:url(rotate.php);}


now this is the css file that is in the theme...I tried it and no go. Blank background, which shows its not working or else it would show my images or a an error image. And its not difficult to setup.

Maybe I need to try a direct URL to the script in the css file.

Login

Who's Online

222 user(s) are online (119 user(s) are browsing Support Forums)


Members: 0


Guests: 222


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits