Javascript 脚本在代码上不断循环,以便在$(document.ready()内创建iframe
下面的代码导致浏览器继续加载,iframe创建似乎陷入无限循环。如果我将iframe创建部件移动到单击事件(例如,Javascript 脚本在代码上不断循环,以便在$(document.ready()内创建iframe,javascript,jquery,asp.net-mvc,html,Javascript,Jquery,Asp.net Mvc,Html,下面的代码导致浏览器继续加载,iframe创建似乎陷入无限循环。如果我将iframe创建部件移动到单击事件(例如,#save)中,则不会出现问题。我需要在页面加载后立即创建iframe,不确定这里缺少了什么 $(document).ready(function() { $('#receiptNum').append(widgetData.processingFormId); //iframe creation part $('<iframe>', { nam
#save
)中,则不会出现问题。我需要在页面加载后立即创建iframe,不确定这里缺少了什么
$(document).ready(function() {
$('#receiptNum').append(widgetData.processingFormId);
//iframe creation part
$('<iframe>', {
name: 'myframe',
id: 'printing',
width: 100,
hieght: 100
}).appendTo('#Mypage');
//Mypage is a popup window
window.open('/Forms/PrintPreviewForm/' + widgetData['processingFormId'], "myframe");
$('#save').click(function() {
window.open('/Forms/GetFormPdf/' + widgetData['processingFormId']);
});
$('#print').click(function() {
window.open('/Forms/PrintPreviewForm/' + widgetData['processingFormId']);
});
});
$(文档).ready(函数(){
$('#receiptNum').append(widgetData.processingFormId);
//iframe创建部分
$('', {
名称:“myframe”,
id:'打印',
宽度:100,
身高:100
}).appendTo(“#Mypage”);
//Mypage是一个弹出窗口
open('/Forms/PrintPreviewForm/'+widgetData['processingFormId'],“myframe”);
$(“#保存”)。单击(函数(){
window.open('/Forms/GetFormPdf/'+widgetData['processingFormId']);
});
$(“#打印”)。单击(函数(){
window.open('/Forms/PrintPreviewForm/'+widgetData['processingFormId']);
});
});
此脚本是否也在您在iframe中打开的页面上?是的,页面会显示一个包含此iframe的弹出窗口(#Mypage)。如果iframe的内容也包含此脚本,则会导致无限循环。每次加载iframe内的页面时,它都会创建一个新的iframe并在其中加载该页面。除了document ready之外,我还可以使用什么好功能来确保只执行一次