当我点击一个按钮并修改将要打开的页面的html和css时,我想打开一个窗口。我该怎么做?
我正在做一个symfony项目,我只想写一段将要打开的窗口。为此,我试了一下:
$( "#tom" ).click(function() {
var wind = window.open("{{ path('AjoutFournisseur') }}", "Ajouter un fournisseur", "width=520,height=1080");
wind.document.getElementById("can").innerHTML='TEST';
});我有个错误:
Uncaught :不能在HTMLSpanElement设置属性'innerHTML‘为null。(加-伏:113) HTMLSpanElement.dispatch (jquery.min.js:2)在HTMLSpanElement.y.handle (jquery.min.js:2)
发布于 2018-07-23 19:00:20
如果弹出窗口与父窗口不在同一个域上,则如果没有来自其他站点的合作,这是不可能的(CORS规则和相同的原产地策略将适用)。
如果两个页面位于同一个域中,则需要进行的更改是等待弹出窗口完成加载,然后尝试修改;现在您正在打开窗口,然后在网络请求有机会返回它们之前立即尝试更改其内容。
我无法在有效的堆栈溢出片段中演示这一点,因为它不允许弹出窗口,但它是这样的:
$('#tom').on("click", function() {
let thePopup = window.open("url_of_popup_window.html");
thePopup.onload = function(e) {
thePopup.document.getElementById("can").innerHTML = 'TEST';
// Or, since you're already using jQuery, use this equivalent to the above line:
// $('#can', e.target).html('TEST'); // e.target is the popup document here
// (this would be usable even if jQuery is not in the popup window, because this script runs in the parent)
}
});https://stackoverflow.com/questions/51480670
复制相似问题