简体   繁体   English

将CSS应用于通过window.open()打开的外部页面

[英]Apply CSS for the external page opened via window.open()

I am opening an external page upon click of a button. 单击按钮后,我将打开一个外部页面。 This is working by using window.open(), the requirement is to apply a specific CSS to the element of external page like changing the font color. 这是通过使用window.open()进行的,要求是将特定的CSS应用于外部页面的元素,例如更改字体颜色。

Can anyone please help me to understand on how to apply CSS to the elements of a external page after opening the external page using window.open() 任何人都可以帮助我了解如何使用window.open()打开外部页面后将CSS应用于外部页面的元素。

You can't, end of story. 你不能,故事的结尾。 This is a security issue built into browsers so scripts from other sites cannot modify other pages. 这是浏览器内置的安全问题,因此其他站点的脚本无法修改其他页面。 This would be a disaster if browsers allowed this. 如果浏览器允许,这将是一场灾难。

You can access the DOM of the child window by accessing the document property of the returned value of the window.open method. 您可以通过访问window.open方法的返回值的document属性来访问子窗口的DOM。

Example: 例:

var popup = window.open("test.html");
popup.document.body.style.backgroundColor = "black";

There will be security issues to deal with when trying to achieve such a goal when the parent domain and child domain differ due to same origin policies. 当父域和子域由于相同的原始策略而不同时,在尝试实现此目标时会遇到安全问题。

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

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