Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/454.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用$(文档).打开新窗口时准备好(功能)_Javascript_Jquery - Fatal编程技术网

Javascript 如何使用$(文档).打开新窗口时准备好(功能)

Javascript 如何使用$(文档).打开新窗口时准备好(功能),javascript,jquery,Javascript,Jquery,当单击运行按钮调用“nwin”函数时,在该函数中我可以使用open()打开新窗口,此时我正在使用该函数,但这不是加载函数。新窗口已打开 这里是按钮代码 $(document).ready(function () { $(".main").onepage_scroll({ sectionContainer: "section", responsiveFallback: 600, loop: true }); }); 当点击这个调

当单击运行按钮调用“nwin”函数时,在该函数中我可以使用open()打开新窗口,此时我正在使用该函数,但这不是加载函数。新窗口已打开

这里是按钮代码

$(document).ready(function () {
    $(".main").onepage_scroll({
        sectionContainer: "section",
        responsiveFallback: 600,
        loop: true
    });
});

当点击这个调用函数时

<div class="resultContainer">
    <div style="height:400px;">
        <div style="float:left; width:100%;  height: 93px; margin: 20px 0 0 60px;"> <span class="containerTitle" style="    top: 65px;">
            <a href="javascript:;" class="button_example"  id="result" style="color: white;">Result</a></span>

        </div>
    </div>
$(“结果”)。单击(nWin);
var htmlEditor=codemirr.fromTextArea(document.getElementById(“html”){
行号:对,
模式:“文本/html”,
对
});
函数nWin(){
htmlEditor.save();
var w=window.open();
$(w.document.head).load(函数(){
$(“.main”).onepage\u滚动({
节容器:“节”,
响应回退:600,
循环:正确
});
});
var script=document.createElement(“脚本”);
script.type=“text/javascript”;
script.src=“jquery.onepage scroll.js”;
$(w.document.head).append(脚本);
$(w.document.head)。附加(“”);
$(w.document.head)。附加(“”);
$(w.document.head).append(“+$('#css').val()+”+$('#js').val());
$(w.document.body).html($('#html').val());
}

尝试将代码放在行
script.src=“jquery.onepage scroll.js”之后
为什么需要使用
document.ready
,而不是在内容后附加
一页滚动脚本?
$("a#result").click(nWin);

var htmlEditor = CodeMirror.fromTextArea(document.getElementById("html"), {
    lineNumbers: true,
    mode: "text/html",
    matchBrackets: true
});

function nWin() {
    htmlEditor.save();
    var w = window.open();
    $(w.document.head).load(function () {
        $(".main").onepage_scroll({
            sectionContainer: "section",
            responsiveFallback: 600,
            loop: true
        });
    });

    var script = document.createElement("script");
    script.type = "text/javascript";
    script.src = "jquery.onepage-scroll.js";
    $(w.document.head).append(script);
    $(w.document.head).append('<link rel="stylesheet" href="onepage-scroll.css" type="text/css" />');
    $(w.document.head).append('<link rel="stylesheet" href="demo_data.css" type="text/css" />');
    $(w.document.head).append("<style>" + $('#css').val() + "</style>" + $('#js').val());
    $(w.document.body).html($('#html').val());
}