Inherit Background from previous page

Discussion in 'Javascript' started by erik, Jul 15, 2003.

  1. erik

    erik Guest

    Is it posssible to inherit the previous pages (parent pages)
    background image? Is there a script out there I could look at? Thanks
     
    erik, Jul 15, 2003
    #1
    1. Advertising

  2. erik

    mike Guest

    Grant Wagner <> wrote in message news:<>...
    > erik wrote:
    >
    > > Is it posssible to inherit the previous pages (parent pages)
    > > background image? Is there a script out there I could look at? Thanks

    >
    > The browser has no way of knowing what the background image of the
    > previous page was. If you want to use the same background image, you'll
    > have to set a cookie with the background image name and read it on each
    > page, or pass the image name around on the URL.


    Not entirly true. I've got what the OP dscribes to work without
    cookies or passing in the url.
    I've only tested it in mozilla 1.4 and I wouldn't like to comment on
    the 'goodness' of the method though :)

    I found part of the answer here -

    http://www.codebelly.com/javascript/backimagechange.html

    If you use the [depricated] background attribute of the body tag to
    specify the image you can change/reference it with javascript. (I
    can't get it to work with body background images defined with css
    though.)

    In the opened window call the following line of javascript with an
    onload on the body tag

    document.body.background=opener.document.body.background



    mike.
     
    mike, Jul 15, 2003
    #2
    1. Advertising

  3. erik

    Peter Guest

    Not sure I see the point of doing this.

    Why not just set up the background-image property in a stylesheet like...

    body { background-image:URL("bg1.gif"); }
    body.specific { background-image:URL("bg2.gif"); }

    Then refer to that from your web pages

    <body class="specific"> which will pick up the bg2.gif background.
    <body> will pick up the bg1.gif background.

    I can see no conceivable purpose for inheriting the background from the
    previous page, just use CSS.

    Peter.

    "mike" <> wrote in message
    news:...
    > Grant Wagner <> wrote in message

    news:<>...
    > > erik wrote:
    > >
    > > > Is it posssible to inherit the previous pages (parent pages)
    > > > background image? Is there a script out there I could look at? Thanks

    > >
    > > The browser has no way of knowing what the background image of the
    > > previous page was. If you want to use the same background image, you'll
    > > have to set a cookie with the background image name and read it on each
    > > page, or pass the image name around on the URL.

    >
    > Not entirly true. I've got what the OP dscribes to work without
    > cookies or passing in the url.
    > I've only tested it in mozilla 1.4 and I wouldn't like to comment on
    > the 'goodness' of the method though :)
    >
    > I found part of the answer here -
    >
    > http://www.codebelly.com/javascript/backimagechange.html
    >
    > If you use the [depricated] background attribute of the body tag to
    > specify the image you can change/reference it with javascript. (I
    > can't get it to work with body background images defined with css
    > though.)
    >
    > In the opened window call the following line of javascript with an
    > onload on the body tag
    >
    > document.body.background=opener.document.body.background
    >
    >
    >
    > mike.
     
    Peter, Jul 17, 2003
    #3
  4. erik

    Grant Wagner Guest

    mike wrote:

    > Grant Wagner <> wrote in message news:<>...
    > > erik wrote:
    > >
    > > > Is it posssible to inherit the previous pages (parent pages)
    > > > background image? Is there a script out there I could look at? Thanks

    > >
    > > The browser has no way of knowing what the background image of the
    > > previous page was. If you want to use the same background image, you'll
    > > have to set a cookie with the background image name and read it on each
    > > page, or pass the image name around on the URL.

    >
    > Not entirly true. I've got what the OP dscribes to work without
    > cookies or passing in the url.
    > I've only tested it in mozilla 1.4 and I wouldn't like to comment on
    > the 'goodness' of the method though :)
    >
    > I found part of the answer here -
    >
    > http://www.codebelly.com/javascript/backimagechange.html
    >
    > If you use the [depricated] background attribute of the body tag to
    > specify the image you can change/reference it with javascript. (I
    > can't get it to work with body background images defined with css
    > though.)
    >
    > In the opened window call the following line of javascript with an
    > onload on the body tag
    >
    > document.body.background=opener.document.body.background
    >
    > mike.


    What you have done is open a new window and accessed the opener's background attribute. This is "inheriting"
    the background image from a previous page. If that is what what the OP meant by "parent" page then sure, he
    could jury rig the setup like this:

    In Internet Explorer use:

    <style type="text/css">
    body { background-image:URL("3dblocks.gif"); }
    </style>
    <body>
    <script type="text/javascript">
    var w = window.open('about:blank');
    w.document.body.style.backgroundImage = document.body.currentStyle.backgroundImage;
    </script>

    And in Mozilla you would use:

    w.document.body.style.backgroundImage = document.defaultView.getComputedStyle(document.body,
    "").backgroundImage;

    Note that on a web site, both pages would have to come from the same domain for this to work, you can't
    specify the backgroundImage for a page loaded in a new window which isn't from your domain.

    Of course, the standard way to handle this is define the background image in one place, then specify:

    <link rel="stylesheet" type="text/css" href="/path/to/file.css" />

    --
    | Grant Wagner <>

    * Client-side Javascript and Netscape 4 DOM Reference available at:
    * http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/frames.html
    * Internet Explorer DOM Reference available at:
    * http://msdn.microsoft.com/workshop/author/dhtml/reference/dhtml_reference_entry.asp
    * Netscape 6/7 DOM Reference available at:
    * http://www.mozilla.org/docs/dom/domref/
    * Tips for upgrading JavaScript for Netscape 6/7 and Mozilla
    * http://www.mozilla.org/docs/web-developer/upgrade_2.html
     
    Grant Wagner, Jul 17, 2003
    #4
  5. erik

    erik Guest

    Thats exactly what I ment - thanks Ill have to give this a whirl

    Erik
     
    erik, Jul 26, 2003
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Greg Krzeszkowski
    Replies:
    3
    Views:
    602
    Peter Blum
    Mar 3, 2005
  2. ABC
    Replies:
    2
    Views:
    455
    John Timney \( MVP \)
    Jan 14, 2006
  3. ABC
    Replies:
    2
    Views:
    432
    libero familymac news
    Jan 14, 2006
  4. Edwin van der Vaart

    transparent and inherit of background

    Edwin van der Vaart, Oct 20, 2005, in forum: HTML
    Replies:
    9
    Views:
    462
    Edwin van der Vaart
    Oct 21, 2005
  5. SerpentKiss2010
    Replies:
    0
    Views:
    2,517
    SerpentKiss2010
    Apr 6, 2011
Loading...

Share This Page