Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
472 views
in Technique[技术] by (71.8m points)

jquery - Load website into DIV

how do i actually retrieve data from a website when i write the URL in a textbox and then hit the submit button. I want the data to be put in an div that i have. Is this possible?

I have tried with this, but it doesn't work!

<script type="text/javascript"> 
function contentDisp()
{
var url = $("#text").val();
$("#contentArea").load(url);
}
</script> 



<textarea id="text">Write URL here</textarea>
<br />
<input type="button" value="Click" onClick="contentDisp();">

<div id="contentArea"></div>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Due to the sandbox on javascript calls, you can't do this (you can't call outside the domain the JS was loaded from), at least not directly

There are 2 methods around this.

The first would be to load the requested url in an iframe rather than a div by setting the src parameter using JS. Simple, easy but would limit your access to the data in the iframe.

The second would be to make an AJAX request on your server and your server then looks up the URL and returns the HTML content (pretty easy to do with CURL or similar). This lets you play around with the returned content a bit more, but again due to the sandbox on cookies you won't be able to request anything like a users facebook page or anything that requires a session as it would be working through the servers session and not the browser session.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...