1

On a internal page you can get the background image easily with jQuery. For example:

var url = $('.headerImg').css('background-image');

But how to get the url from an external website ? For a better understanding what is meant here - of course this is not possible:

var url = $('www.website.de:/.headerImg').css('background-image');

Is there any way?

Christian Michael
  • 2,128
  • 1
  • 19
  • 27

2 Answers2

0

Try like this,

$("body").css("background-image", "url('https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcTALmLDCnfMHOLz6NTj8Sxy5X6A--LYF7j0lT9Uoq7bU6LdImY')");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
Dimag Kharab
  • 4,439
  • 1
  • 24
  • 45
0

Using JQuery AJAX

$.get( "your-url", function( data ) {
  // display the loaded HTML: $( ".result" ).html( data );
  //data is the loaded html page. You can select the element you want from here
  // like $('.headerImg').css('background-image');
});

For more documentation see https://api.jquery.com/jquery.get/

Dirk Jan
  • 2,355
  • 3
  • 20
  • 38
  • I guess it's not allowed to load content with ajax from external website. – Christian Michael Feb 01 '16 at 08:42
  • So.. You want the bg image from another website HTML without knowing the url.. Than you have to load the full website inside your project with an iframe i think. – Dirk Jan Feb 01 '16 at 08:54
  • @ChristianMichael see this post: http://stackoverflow.com/questions/14999573/jquery-load-external-site-page maybe this will help? – Dirk Jan Feb 01 '16 at 09:26