[JAVASCRIPT] functie retouneert geen string in FF

Pagina: 1
Acties:

Acties:
  • 0 Henk 'm!

  • Spiral
  • Registratie: December 2005
  • Niet online
Ik wil de achtergrond aanpassen. In IE7 werkt deze javascript functie maar in FF3 niet.

JavaScript:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
function getBackgroundUrl(_width, _height, _rgb)
{
    if(_rgb == undefined)
    {
        var _rgb = "0, 119, 255"; 
    }
    
    return "url(background.php?width=" + _width + "&height=" + _height + "&rgb=" + _rgb + ")";
}

function setSiteBackground()
{
    var width = 0;
    var height = 0;
    
    if (window.innerWidth && window.innerHeight)
    { 
        width = window.innerWidth; 
        height = window.innerHeight; 
    } 
    //IE Mozilla 
    if (document.body.clientWidth && document.body.clientHeight)
    { 
        width = document.body.clientWidth; 
        height = document.body.clientHeight; 
    } 

    document.getElementById("container").style.backgroundImage = getBackgroundUrl(width,height, "12,12,12");
}


als ik regel 28 verander in het volgende dan werkt het in zowel IE als FF3:
JavaScript:
1
document.getElementById("container").style.backgroundImage = "url(background.php?width=" + width + "&height=" + height + "&rgb=12,12,12)";


Waarom werkt het eerste niet? Ik heb via alert(getBackgroundUrl()) al geverifieerd dat hij de goede output genereerd. Ik weet ook niet hoe ik dit probleem moet benoemen om te googlen

To say of what is that it is not, or of what is not that it is, is false, while to say of what is that it is, and of what is not that it is not, is true. | Aristoteles


Acties:
  • 0 Henk 'm!

  • UltimateB
  • Registratie: April 2003
  • Niet online

UltimateB

Pomdiedom

werkt het wel als je regel 28 maakt:

JavaScript:
1
    document.getElementById("container").style.backgroundImage = "" + getBackgroundUrl(width,height, "12,12,12"); 

"True skill is when luck becomes a habit"
SWIS


Acties:
  • 0 Henk 'm!

  • Snake
  • Registratie: Juli 2005
  • Laatst online: 07-03-2024

Snake

Los Angeles, CA, USA

En als je debugt in Firefox met Firebug? Wat het type is enzo? Dit is eigelijk basic debugwerk.

Going for adventure, lots of sun and a convertible! | GMT-8


Acties:
  • 0 Henk 'm!

  • Spiral
  • Registratie: December 2005
  • Niet online
UltimateB schreef op zondag 02 november 2008 @ 19:15:
werkt het wel als je regel 28 maakt:

JavaScript:
1
    document.getElementById("container").style.backgroundImage = "" + getBackgroundUrl(width,height, "12,12,12"); 
Nee dat werkt helaas ook niet Ik heb ook meteen maar " ' " geprobeerd en dat uiteraard ook toegevoegd aan het einde. Zoals hieronder. Dit mocht ook niet baten
JavaScript:
1
    document.getElementById("container").style.backgroundImage = "'" + getBackgroundUrl(width,height, "12,12,12") + "'"; 


Ik vind het heel vreemd! Dit is wel mijn eerste dagje met javascript btw

To say of what is that it is not, or of what is not that it is, is false, while to say of what is that it is, and of what is not that it is not, is true. | Aristoteles


Acties:
  • 0 Henk 'm!

  • Spiral
  • Registratie: December 2005
  • Niet online
Snake schreef op zondag 02 november 2008 @ 19:20:
En als je debugt in Firefox met Firebug? Wat het type is enzo? Dit is eigelijk basic debugwerk.
Ik weet niet wat je met type bedoeld maar het geldt voor een <div id="container">

To say of what is that it is not, or of what is not that it is, is false, while to say of what is that it is, and of what is not that it is not, is true. | Aristoteles


Acties:
  • 0 Henk 'm!

  • Snake
  • Registratie: Juli 2005
  • Laatst online: 07-03-2024

Snake

Los Angeles, CA, USA

-

[ Voor 100% gewijzigd door Snake op 02-11-2008 19:54 ]

Going for adventure, lots of sun and a convertible! | GMT-8


Acties:
  • 0 Henk 'm!

  • Haan
  • Registratie: Februari 2004
  • Laatst online: 15:57

Haan

dotnetter

Probeer anders eens:
JavaScript:
1
2
var background = getBackgroundUrl(width,height, "12,12,12");
document.getElementById("container").style.backgroundImage = background;

Kater? Eerst water, de rest komt later


Acties:
  • 0 Henk 'm!

  • Spiral
  • Registratie: December 2005
  • Niet online
AARRGGHH Opgelost!

JavaScript:
1
2
3
4
5
6
7
8
9
function getBackgroundUrl(_width, _height, _rgb)
{
    if(_rgb == undefined)
    {
        var _rgb = "0, 119, 255"; 
    }
    
    return "url(background.php?width=" + _width + "&height=" + _height + "&rgb=" + _rgb + ")";
}


Het waren de spaties in _rgb die het 'm deden. IE7 verwijderd ze waarschijnlijk.
In background.php doe ik o.a. het volgende
PHP:
1
$rgb_values = explode(",",$_REQUEST["rgb"]);


Waarschijnlijk gaan de spaties verloren in IE7

To say of what is that it is not, or of what is not that it is, is false, while to say of what is that it is, and of what is not that it is not, is true. | Aristoteles

Pagina: 1