admin管理员组文章数量:1416317
How can I use JavaScript/jQuery to populate a popup-window with data from JS-variables in the parent page?
In my example I have an array of filenames. I list at most five in the parent window and if there's more I want to provide a link that opens a popup window and lists each post in the array.
So if I open a popup that contains a <ul id="all_files"></ul>
, how can I add <li>
-items to that list?
How can I use JavaScript/jQuery to populate a popup-window with data from JS-variables in the parent page?
In my example I have an array of filenames. I list at most five in the parent window and if there's more I want to provide a link that opens a popup window and lists each post in the array.
So if I open a popup that contains a <ul id="all_files"></ul>
, how can I add <li>
-items to that list?
- are file names already available in the parent window? if not how do you get the first 5 names? – TheVillageIdiot Commented Nov 16, 2009 at 8:19
- Yes, they are collected with Ajax and stored in an array in the parent window. – Christoffer Commented Nov 16, 2009 at 8:23
1 Answer
Reset to default 3Parent Window:
<span id="popup"> Click to Open Popup </span>
<script type="text/javascript">
var ar=new Array("Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6",
"Item 7", "Item 8", "Item 9", "Item 10");
function getArray(){
return ar;
}
$(document).ready(function(){
$("span#popup").click(function(){
var p=window.open("Popup.html");
});
});
</script>
Popup Window:
<ul id="list"></ul>
<script type="text/javascript">
if(window.opener && !window.opener.closed){
var ar= window.opener.getArray();
var items="";
for(var i=0;i<ar.length;i++){
items +="<li>" + ar[i] + "</li>";
}
$("ul#list").html(items);
}
</script>
本文标签: javascriptHow to open popup and populate it with data from parent windowStack Overflow
版权声明:本文标题:javascript - How to open popup and populate it with data from parent window? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745244007a2649471.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论