am creating a jquery modal dialog and linking it to a form in another page like this:
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?
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="myiframe" style="border: 0px; " src="' + page + '" width="100%" height="100%"></iframe>'
and then simply
document.getElementById('myiframe').contentWindow.document
see if this is something you need: 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">
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.