开发者

How to pass data from Parent window to pop-up window

开发者 https://www.devze.com 2023-03-22 10:35 出处:网络
parent window is : http://localhost:8080/webApp/index.htmlby clicking on given Button, a pop-up window appears and i want to send some data as innerHTML from parent window to pop-up window.

parent window is : http://localhost:8080/webApp/index.html by clicking on given Button, a pop-up window appears and i want to send some data as innerHTML from parent window to pop-up window. i am using below function to appear the pop-up window

<script type = text/javascript>
     window.open("popup.html", "popup",'toolbar = no, status = no beforeShow');
</script>

popup window url is : http://localhost:8080/webApp/popup.html

Now i want to send data (innerHTML text) from parent window to popup window and i know it can be post to server using AJAX and then add into popup page, But i do not want to send this innerHTML text (data) to server, I just want to use js function to perform my task at client side only. Is it possible?

server side : java, servlet
Client Side : 开发者_JAVA技巧jQuery, javascript


why not try simple window handler like:

x = window.open("....","..","...");
x.document.write("bla bla bla");

The idea here is, when we do refer only document.write and other document level command it refers to current window ie. if we say document.getElementById("xxx") then its actually for current window like window.document.getElementById("xxx"); If we want it from popup window then we need to assign a handler for that window using:

x = window.open(".....")

and we can use that handler to perform as same as in current window. instead of document.getElementByID use x.document.getElementById

Hope this helps.


Try this :

parent window js :  window.open("popup.html", "popup",'toolbar = no, status = no beforeShow');

children/pop-up window js : window.opener.document.getElementById("parent_window_id").innerHTML;

Normally you can not access any function or data of parent window from Child/popup window unless you use window.opener = parent window (this is just reference of parent window) and then get any id, function or data(innerHTML)


If you just need to pass some data, you can add a global variable to your popup by saving the return value of window.open and then setting a property on it. If you want to manipulate the HTML of the popup window, you can create a jQuery object of the popup window's body.

var popup = window.open("popup.html", "popup",'toolbar = no, status = no beforeShow');
popup.dataFromParent = 'Some Data';

var $popupBody = $(popup.document.body);
// Manipulate $popupBody just like you would any other jQuery object.
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号