admin管理员组文章数量:1326513
Does anyone know how to load content into a div of external HTML page with jQuery?
Using $('#divname').html("content")
only seems to be able to access div
elements of the HTML page where the script is in.
Does anyone know how to load content into a div of external HTML page with jQuery?
Using $('#divname').html("content")
only seems to be able to access div
elements of the HTML page where the script is in.
- What does "external" means here, another page from same domain or from any other domain? – Vipul Commented Dec 15, 2012 at 17:18
- A page from the same domain. – MaVe Commented Dec 15, 2012 at 19:35
- Please have a look at my answer. And if my assumption is incorrect, please add more code to explain what you want to do – DivZero Commented Dec 15, 2012 at 20:13
- @DivZero Well, my pages are in different folders, but I guess this is till the same domain? Or do I need to set these domains explicitly? – MaVe Commented Dec 16, 2012 at 8:22
4 Answers
Reset to default 3If I understand correctly you want to change the content of a DIV of an external page like for example an iframe?
If so, this can't be done with simple jQuery due to security reasons
You can use load()
to load all content , or target specific content from remote page into an element in local page. load()
is an AJAX method. Do a little research on AJAX
$('#myDiv').load('remotePageUrl')
Or to only get part of the remote page
$('#myDiv').load('remotePageUrl #remotePageID')
API Reference: http://api.jquery./load/
Found it! This is what I needed:
access div in iframe parent
I thought I didn't matter that it was a child-parent relationship as long they were in the same domain, but apparently it does.
Thanks for the responses!
$.get("test.php", function(data){
$("div").html(data);
});
本文标签: javascriptLoad content into div of external html page with JQueryStack Overflow
版权声明:本文标题:javascript - Load content into div of external html page with JQuery - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742200985a2431954.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论