简体   繁体   English

使用window.opener或其他方法将javascript变量值从弹出窗口设置为父窗口

[英]Setting javascript variable value from Pop-Up window to the parent using window.opener or something else

I have an HTML page (Lets call this Parent Page), from where a new Pop-Up (Child Page) can be opened by clicking on a link. 我有一个HTML页面(称为“父页面”),可以通过单击链接从其中打开新的弹出窗口(子页面)。 But I am in situation to set the Parent page's javascript variable by using the javascript processing on this pop-up page. 但是我有一种情况是通过使用此弹出页面上的javascript处理来设置“ 父”页面的 javascript变量。

I tried using window.opener but it results into error Uncaught TypeError: Cannot set property 'parent_page_var' of null 我尝试使用window.opener,但导致错误Uncaught TypeError: Cannot set property 'parent_page_var' of null

I can also use jQuery if the it provides resolution, but I'll prefer Javascript. 如果jQuery提供解析度,我也可以使用jQuery,但我更喜欢Javascript。

PS: Everything is there on same domain, so there is no CORS thing required. PS:一切都在同一个域中,因此不需要CORS。 I just want a simple solution 我只想要一个简单的解决方案

Here is the code for window.opener: 这是window.opener的代码:

window.opener.parent_page_var = pop_up_variable_value;

IN the child page: 在子页面中:

window.opener.parent_page_var.value = document.child_form_name.field_name.value;
self.close();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM