最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Send data to separate window javascript - Stack Overflow

programmeradmin4浏览0评论

I created a new popup window from an existing page using:

window.open("myUrl","myName","width=200,height=200");

Now on that popup window I have a text input and a button, I want to create an onclick method for the button that sends the text inputs value to the page that created the popup without using a form or php, is this possible?

I created a new popup window from an existing page using:

window.open("myUrl","myName","width=200,height=200");

Now on that popup window I have a text input and a button, I want to create an onclick method for the button that sends the text inputs value to the page that created the popup without using a form or php, is this possible?

Share Improve this question edited Sep 19, 2014 at 10:32 BenMorel 36.7k52 gold badges206 silver badges337 bronze badges asked May 24, 2012 at 6:11 StuyvensteinStuyvenstein 2,4472 gold badges28 silver badges36 bronze badges 1
  • 2 stackoverflow./questions/9994120/… – Ja͢ck Commented May 24, 2012 at 6:35
Add a ment  | 

3 Answers 3

Reset to default 6

you can use the window.opener keyword

lets say you have a javascript method doSomething(value){....} in your parent class, then from your POPUP you can call the parent function using

window.opener.doSomething("here is my data from child sent to parent");

UPDATED

Assuming both the parent and the new window are on the same domain, you should be able to directly manipulate their JS environment:

var w = window.open("myUrl", "myName", "width=200,height=200");
var e = w.document.getElementById('someId');
// do something with element e

If they are on different domains, you might need to use window.postMessage or other cross-domain messaging techniques, if window.postMessage is not supported by your targeted browsers.

Any open window call forms a get request to new window. This is very simple way that you pass the params you want to send using URL itself like,

var myUrl = "http://example./test?myName=" + myName;
window.open(myUrl,"windowName","width=200,height=200");

Now on the page you can get myName as a request parameter. Please try this.

发布评论

评论列表(0)

  1. 暂无评论