Everdaylifelessons
Everdaylifelessons

Reputation: 1

How can I set my pages background image to the referring page's background image

So this it it I've been trying all day to use javascript or jquery to set my page's background to the same background of whatever page is the referring url so far this is what I have

<script>
var xyz=document.referrer;
var urz=xyz.body.style.backgroundImage;
document.body.style.backgroundImage = urz;
</script>

Any help would be greatly appreciated!

Upvotes: 0

Views: 1178

Answers (1)

Simon Fischer
Simon Fischer

Reputation: 1196

Short answer is: This cannot work since document.referrer is a URI, not the referring document.

In theory, you could load that page (again) and do a lot of magic to obtain its background image. In general however (i.e. if the referrer can be any page), you won't be able to load it from Javascript anyway due to all kinds of security restrictions.

If in your use case you are in control of the referring page it is probably best to find a different solution to pass that information to the navigation target, but you would have to be more clear on your use case.

Upvotes: 1

Related Questions