Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
564 views
in Technique[技术] by (71.8m points)

javascript - How to get access of document object of a window opened with window.open?

I open a website in a new tab through javascript by writing the following code in the browser console:

var win = window.open("http://staging.redefinewebs.in/wildgoose-const/wp-admin/post-new.php", "mywin", '');

Now I want to add text in a field in the newly opened tab. But for that I need the access to win.document. When I write win.document in the console I get the following error:

Error: Permission denied to access property "document"

This error doesn't appear if I open other websites in new tab. So,

How to get access of document object of a window opened in a new tab with window.open?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You cannot access a child window's DOM, if it violates the Same Origin Policy.

You can access the DOM of a child window, only if the following three conditions are satisfied.

  • Both windows have same protocol (http/https)
  • Both windows have same host (google.com and news.google.com are different)
  • Both windows have same port (google.com:80 and google.com:443 are different)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...