javascript 使用自定义内容而不是 url 创建窗口弹出窗口?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20420462/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 18:27:00  来源:igfitidea点击:

Create window popup with custom content instead of url?

javascriptjqueryhtmlcsspopup

提问by Vignesh Pichamani

Any one let me give an idea of implementing the window popup and accessing the jsvariable of parent window to popup window with custom content.

任何人都让我想到实现窗口弹出窗口并访问js父窗口的变量以使用自定义内容弹出窗口。

<div id="modeltext" style="display:none">
    <p id="linker" ></p>
    <script type="text/javascript">
        var news = "http://google.com";
        jQuery(document).ready(function() {
        jQuery('#linker').html("<a href="+news+">"+news+"</a>");
        });
    </script>
    This is for testing according to the concept.

</div>
<a href="#" id="testing" >Open a popup window</a>

JS:

JS:

jQuery('#testing').click(function() {

  var w = window.open($('', "", "width=600, height=400, scrollbars=yes"));
        alert(news);


        var $w = $(w.document.body);

        $w.html($('#modelText').html());
});

For example:

例如:

Let consider i have set of set of paragraph and simple html form. If some one click the link from the parent like (Open in New Window). Instead of url, i want to load the custom content and also i can't able to access the js variable value to the popup window. Not sure any suggestion would be great. I try to provide the js fiddle but the popup is not working. Is there is a way to show the custom content to the popup instead of url and using the js variable from main window to the popup window ?(How to get the window popup load in the parent window). Fiddle not working But here is the code http://jsfiddle.net/6cpup/11/

让我们考虑一下我有一组段落和简单的 html 表单。如果有人单击来自父级的链接,例如(Open in New Window)。我想加载自定义内容而不是 url,而且我无法访问弹出窗口的 js 变量值。不确定任何建议都会很棒。我尝试提供 js 小提琴,但弹出窗口不起作用。有没有办法将自定义内容显示到弹出窗口而不是 url 并使用从主窗口到弹出窗口的 js 变量?(如何在父窗口中加载窗口弹出窗口)。小提琴不起作用但这里是代码 http://jsfiddle.net/6cpup/11/

回答by roo2

EDIT:

编辑:

I think it was caused because you incorrectly opened the window, check out this jsFiddle

我认为这是因为你错误地打开了窗口,看看这个 jsFiddle

 var w = window.open('', "", "width=600, height=400, scrollbars=yes");
    //alert(ICJX_JXPath);

 var html = $("#modeltext").html();

 $(w.document.body).html(html);

For the popup with custom HTML, check out this answer Open window in JavaScript with HTML inserted

对于带有自定义 HTML 的弹出窗口,请查看此答案在 JavaScript 中打开窗口并插入 HTML