am creating a jquery modal dialog and linking it to a form in another page like this:
我正在创建一个jquery模式对话框并将其链接到另一个页面中的表单,如下所示:
var $dialog = $("<div></div>")
.html('<iframe style="border: 0px; " src="' + page + '" width="100%" height="100%"></iframe>')
.dialog({
autoOpen: false,
modal: true,
height: 400,
width: 300,
title: "Multiple HAWBs",
buttons: {
"Save": function() {
$( this ).dialog( "close" );
},
"Cancel": function() {
$( this ).dialog( "close" );
}
},
close: function() {}
});
$dialog.dialog('open');
});
on the linked page I have a element and I am trying to read the selected values from the dialog to my parent page, how canI do this?
在链接页面上我有一个元素,我试图从对话框中读取选定的值到我的父页面,我怎么能这样做?
2 个解决方案
#1
0
If iframe's source is different domain, you can't do that. In other case you can access its content by adding an id to that element
如果iframe的源是不同的域,则不能这样做。在其他情况下,您可以通过向该元素添加id来访问其内容
<iframe id="myiframe" style="border: 0px; " src="' + page + '" width="100%" height="100%"></iframe>'
and then simply
然后简单地说
document.getElementById('myiframe').contentWindow.document
#2
0
see if this is something you need:HERE
看看这是否是你需要的东西:HERE
demo.php
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://code.jquery.com/ui/1.11.1/jquery-ui.min.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.11.1/themes/smoothness/jquery-ui.css" />
<script>
$(document).ready(function(){
$(".click").on('click',function(){
myDialog();
});
});
function myDialog(){
var $dialog = $("<div></div>")
.html('<iframe style="border: 0px;" id="frame" src="view1.php" width="100%" height="100%"></iframe>')
.dialog({
autoOpen: false,
modal: true,
height: 400,
width: 300,
title: "Multiple HAWBs",
buttons: {
"Save": function() {
var data="";
var childrens= $($(document.getElementById('frame').contentWindow.document)[0].activeElement).children();//get allthe fields of dialog
childrens.each(function(index){
if(childrens[index].id == 'addme1'){
data=data+childrens[index].value;//this is just to show you the reading of content of dialog.
}
})
$( this ).empty();
$("#parent").html(data);
$( this ).dialog( "close" );
},
"Cancel": function() {
$( this ).dialog( "close" );
}
},
close: function() {
}
});
$dialog.dialog('open');
}
</script>
<div>
<div id="parent">i'll be changed using dialog data</div>
<button class="click">Open Dialog</button>
view1.php
<input type="text" id="addme">
<input type="text" id="addme1">
#1
0
If iframe's source is different domain, you can't do that. In other case you can access its content by adding an id to that element
如果iframe的源是不同的域,则不能这样做。在其他情况下,您可以通过向该元素添加id来访问其内容
<iframe id="myiframe" style="border: 0px; " src="' + page + '" width="100%" height="100%"></iframe>'
and then simply
然后简单地说
document.getElementById('myiframe').contentWindow.document
#2
0
see if this is something you need:HERE
看看这是否是你需要的东西:HERE
demo.php
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://code.jquery.com/ui/1.11.1/jquery-ui.min.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.11.1/themes/smoothness/jquery-ui.css" />
<script>
$(document).ready(function(){
$(".click").on('click',function(){
myDialog();
});
});
function myDialog(){
var $dialog = $("<div></div>")
.html('<iframe style="border: 0px;" id="frame" src="view1.php" width="100%" height="100%"></iframe>')
.dialog({
autoOpen: false,
modal: true,
height: 400,
width: 300,
title: "Multiple HAWBs",
buttons: {
"Save": function() {
var data="";
var childrens= $($(document.getElementById('frame').contentWindow.document)[0].activeElement).children();//get allthe fields of dialog
childrens.each(function(index){
if(childrens[index].id == 'addme1'){
data=data+childrens[index].value;//this is just to show you the reading of content of dialog.
}
})
$( this ).empty();
$("#parent").html(data);
$( this ).dialog( "close" );
},
"Cancel": function() {
$( this ).dialog( "close" );
}
},
close: function() {
}
});
$dialog.dialog('open');
}
</script>
<div>
<div id="parent">i'll be changed using dialog data</div>
<button class="click">Open Dialog</button>
view1.php
<input type="text" id="addme">
<input type="text" id="addme1">