hi. i want to assign different background image to a web page according to
the query string in the URL. so i write this javascript ...


thisURL = window.location;
if (thisURL.indexOf('bio') != -1) {
document.body.background = "bg2.jpg"
}


... only to find that it doesn't work!

what is wrong with it? thanks.

--
Xero

http://www.chezjeff.net
My personal web portal

Re: need help making a javascript work by MD

MD
Mon Aug 21 13:25:23 CDT 2006

Hi Xero,

The problem is that you're getting the object "location" versus the URL string which is contained in window.location.href.

--
Mike
http://www.websunlimited.com
FrontPage Add-in
MVP FrontPage '97 - '02


"Xero" <jeff_at_chezjeff_dot_net> wrote in message news:688B75BE-360E-419F-929C-31187D80CD02@microsoft.com...
> hi. i want to assign different background image to a web page according to
> the query string in the URL. so i write this javascript ...
>
>
> thisURL = window.location;
> if (thisURL.indexOf('bio') != -1) {
> document.body.background = "bg2.jpg"
> }
>
>
> ... only to find that it doesn't work!
>
> what is wrong with it? thanks.
>
> --
> Xero
>
> http://www.chezjeff.net
> My personal web portal



Re: need help making a javascript work by Trevor

Trevor
Tue Aug 22 02:08:25 CDT 2006

Xero wrote:
> hi. i want to assign different background image to a web page
> according to the query string in the URL. so i write this javascript
> ...
>
>
> thisURL = window.location;
> if (thisURL.indexOf('bio') != -1) {
> document.body.background = "bg2.jpg"
> }
>
>
> ... only to find that it doesn't work!
>
> what is wrong with it? thanks.

To retrieve a query string use
function qsobj(parm)
{
var qpairs = document.location.search.substring(1).split("&")
var qvbl = qpairs[parm].split("=")
return qvbl[1] ? unescape(qvbl[1].replace(/%20|\ +/g," ")) : null
}

So if you call the page as
thepage.html?bgcol=bg2.jpg
then the JS in thepage.html would be (not tested)
<head>

<script type="text/javascript">
function qsobj(parm)
{
var qpairs = document.location.search.substring(1).split("&")
var qvbl = qpairs[parm].split("=")
return qvbl[1] ? unescape(qvbl[1].replace(/%20|\ +/g," ")) : null
}
document.body.background = qsobj(0)
</script>

</head>
--
Cheers,
Trevor L.
[ Microsoft MVP - FrontPage ]
MVPS Website: http://trevorl.mvps.org/

Re: need help making a javascript work by MD

MD
Tue Aug 22 09:21:34 CDT 2006

I'm confused how does this have anything to do with the question asked?

--
Mike
http://www.websunlimited.com
FrontPage Add-in
MVP FrontPage '97 - '02

"Trevor L." <Trevor_L.@Canberra> wrote in message news:O7wWtnbxGHA.5040@TK2MSFTNGP03.phx.gbl...
> Xero wrote:
>> hi. i want to assign different background image to a web page
>> according to the query string in the URL. so i write this javascript
>> ... thisURL = window.location;
>> if (thisURL.indexOf('bio') != -1) {
>> document.body.background = "bg2.jpg"
>> }
>>
>>
>> ... only to find that it doesn't work!
>>
>> what is wrong with it? thanks.
>
> To retrieve a query string use
> function qsobj(parm)
> {
> var qpairs = document.location.search.substring(1).split("&")
> var qvbl = qpairs[parm].split("=")
> return qvbl[1] ? unescape(qvbl[1].replace(/%20|\ +/g," ")) : null
> }
>
> So if you call the page as thepage.html?bgcol=bg2.jpg then the JS in thepage.html would be (not tested)
> <head>
>
> <script type="text/javascript">
> function qsobj(parm)
> {
> var qpairs = document.location.search.substring(1).split("&")
> var qvbl = qpairs[parm].split("=")
> return qvbl[1] ? unescape(qvbl[1].replace(/%20|\ +/g," ")) : null
> } document.body.background = qsobj(0)
> </script>
>
> </head>
> --
> Cheers,
> Trevor L.
> [ Microsoft MVP - FrontPage ]
> MVPS Website: http://trevorl.mvps.org/



Re: need help making a javascript work by MD

MD
Tue Aug 22 09:48:17 CDT 2006

Never mind I see what you're doing.

--
Mike
http://www.websunlimited.com
FrontPage Add-in
MVP FrontPage '97 - '02

"MD Websunlimited" <none@none.com> wrote in message news:udBIIZfxGHA.4764@TK2MSFTNGP02.phx.gbl...
> I'm confused how does this have anything to do with the question asked?
>
> --
> Mike
> http://www.websunlimited.com
> FrontPage Add-in
> MVP FrontPage '97 - '02
>
> "Trevor L." <Trevor_L.@Canberra> wrote in message news:O7wWtnbxGHA.5040@TK2MSFTNGP03.phx.gbl...
>> Xero wrote:
>>> hi. i want to assign different background image to a web page
>>> according to the query string in the URL. so i write this javascript
>>> ... thisURL = window.location;
>>> if (thisURL.indexOf('bio') != -1) {
>>> document.body.background = "bg2.jpg"
>>> }
>>>
>>>
>>> ... only to find that it doesn't work!
>>>
>>> what is wrong with it? thanks.
>>
>> To retrieve a query string use
>> function qsobj(parm)
>> {
>> var qpairs = document.location.search.substring(1).split("&")
>> var qvbl = qpairs[parm].split("=")
>> return qvbl[1] ? unescape(qvbl[1].replace(/%20|\ +/g," ")) : null
>> }
>>
>> So if you call the page as thepage.html?bgcol=bg2.jpg then the JS in thepage.html would be (not tested)
>> <head>
>>
>> <script type="text/javascript">
>> function qsobj(parm)
>> {
>> var qpairs = document.location.search.substring(1).split("&")
>> var qvbl = qpairs[parm].split("=")
>> return qvbl[1] ? unescape(qvbl[1].replace(/%20|\ +/g," ")) : null
>> } document.body.background = qsobj(0)
>> </script>
>>
>> </head>
>> --
>> Cheers,
>> Trevor L.
>> [ Microsoft MVP - FrontPage ]
>> MVPS Website: http://trevorl.mvps.org/
>
>