0

i want to display only one div from a Website.

--

this site shows the hole site-content http://www.dict.cc/?s=house (house should be dynamic, this search-expression isn't fix.)

and now the result should view only the div with the picture. but I don't know to do this. I found out, that this div called "slide0". I have this: ____________________________> but the result should look like this:

enter image description here __________>enter image description here

Josh Crozier
  • 233,099
  • 56
  • 391
  • 304
  • Is your page on the same domain as the div you are trying to access? – Lance Jun 03 '15 at 16:15
  • @Lance: when you copy my code in a file and open it with the browser, then it should work. but my code doesn't work. (no it is not the same domain) ..mmh – user3875103 Jun 03 '15 at 19:04
  • I see the whole page in the div. What do you see? And what do you want? – Lance Jun 03 '15 at 20:55
  • @Lance: Yes, i also see the whole page in the div. - but i only want to see the house like above. (it is the div: slide0) – user3875103 Jun 03 '15 at 23:36
  • I believe the Same Origen Policy will prevent you from doing this, at least this way. Do you have PHP installed on your server? – Lance Jun 03 '15 at 23:49
  • @Lance: i don't know if php will work.. it should be placed in Android (WebView) – user3875103 Jun 04 '15 at 00:04
  • You would use php to retrieve the div from the remote page and then insert it into your final page. – Lance Jun 04 '15 at 00:40
  • @Lance: and how would that code looks like? – user3875103 Jun 04 '15 at 00:50
  • Give me a few minutes. I'm working on it now and will post it as an answer below when it's done. – Lance Jun 04 '15 at 00:52
  • Okay, the way they build the page, that's not going to work either. What, exactly, is your desired result? Do you just want the picture of the house? – Lance Jun 04 '15 at 01:22
  • @Lance: yes, i just want the piture of the house.. ..i don't get it. :/ – user3875103 Jun 04 '15 at 11:49
  • Okay, @user3875103, then I think you are over complicating this a great deal. I will post my answer below. – Lance Jun 04 '15 at 15:11
  • Same Origin Policy can be [disabled for a WebView in Android](http://stackoverflow.com/a/13740831/2784939), then you'd just use an Ajax call to get the data you need – René Roth Jun 06 '15 at 12:43

1 Answers1

-1

If I understand correctly, the url

"http://www.dict.cc/?s=house"

returns the bytes representing an image.

If this is true, why not just use an image instead of a div?

<body>
<img id="result">
</body>

 <script type="text/javascript">
    $(document).ready(function() {   
            $("#result").src("http://www.dict.cc/?s=house");
    });
</script>

However, it looks like you're trying to use an image from another site. If so, you'll need permission to do that, and then when you get permission, simply use the complete URL of the image, not the entire web page URL.

Blamkin86
  • 1,029
  • 8
  • 8
  • The link doesn't return an image, it returns a web page. – George Jun 03 '15 at 16:18
  • "If I understand correctly, the url returns the bytes representing an image." – George Jun 03 '15 at 16:20
  • but, the URL from image is not always the same. It depends to the link. ...cause http://www.dict.cc/?s=house can also be http://www.dict.cc/?s=talbe – user3875103 Jun 03 '15 at 16:25
  • @user3875103 Are you wanting to display someone else's website within your own? Is that what you're after? – Blamkin86 Jun 03 '15 at 16:25
  • i want to show a part(the div) from another website within my website. – user3875103 Jun 03 '15 at 16:34
  • @Blamkin86: thanks for this idea, but i don't know to solve it. :/ ..can you post the code for my example, please. :-) – user3875103 Jun 03 '15 at 16:45
  • I'm not comfortable doing so. Please read the following: http://stackoverflow.com/questions/364952/jquery-javascript-accessing-contents-of-an-iframe – Blamkin86 Jun 03 '15 at 17:11
  • now this contains my body: `` and which way should i select for the solution? 1) `$(document).ready(function(){ $('#frameID').load(function(){ $('#frameID').contents().find('slide0').html('test it!!'); }); });` 2) `document.getElementById('iframe').contentWindow.document.body.innerHTML` or 3)`$('#frameID').contents().find('div#slide0).html();` ? i don't understand how to solve.. :( – user3875103 Jun 03 '15 at 17:51