[英]How do I correctly set a background image to a pop up window in javascript?
I am trying to set a background image to a pop up menu in javascript, I have seen a lot of answers but none it is working for me.我正在尝试将背景图像设置为 javascript 中的弹出菜单,我看到了很多答案,但没有一个对我有用。 I do not know If I correctly write the path of the image, I think it is fine.
不知道如果我把图片的路径写对了,我觉得还好。 The data is loaded inside the pop up windows is through ajax, so I try to put php code with html to set the background but it is not working.
弹出窗口中的数据是通过ajax加载的,所以我尝试将php代码与html一起放置来设置背景,但它不起作用。 Please help I am stuck
请帮助我被卡住
This is my code :这是我的代码:
$.post('nacimientos/controller/controllerGuardarNacimiento.php',{'nss':nss, 'nombre':nombre, 'apellidos':apellidos, 'sexo':sexo, 'peso':peso, 'talla': talla, 'hora':hora}, function(data){
var left = ($(window).width() / 2) - (900 / 2);
var top = ($(window).height() / 2) - (600 / 2);
WinId = window.open('', 'newwin', 'width=900,height=800,scrollbars=0, menubar=0,top= ' + top + ', left='+left);
WinId.document.open();
WinId.document.writeln("<body style='background-image: url('imagen3.jpg')'>");
WinId.document.write(data);
WinId.document.writeln("<\/body>");
WinId.document.close();
});
The other code is the data that is loaded in the pop up is :另一个代码是弹出窗口中加载的数据是:
echo "<div align='center'>";
echo "<h1>Felicidades!!</h1>";
echo "</div>";
echo "<div align='center'>";
foreach($resultado2 as $value){
echo "<label for=''><h3>Nacimiento no: </h3></label><h3>".$value['id_nacimiento']."</h3>";
echo "<label for=''><h3>Número de Seguridad Social (NSS):</h3></label><h3>".$value['nss']."</h3>";
echo "<label for=''><h3>Nombre:</h2></label><h3>".$value['nombre']." ".$value['apellidos']."</h3>";
echo "<label for=''><h3>Sexo:</h3></label><h3>"; if($value['sexo'] == 'm'){ echo "Hombre";} else{ echo "Mujer";} echo "</h3>";
echo "<label for=''><h3>Peso:</h3></label><h3>".$value['peso']." "."gramos</h3>";
echo "<label for=''><h3>Talla:</h2></label><h3>".$value['talla']." "."cm</h3>";
echo "<label for=''><h3>Hora de nacimiento:</h3></label><h3>".$value['hora']."</h3>";
}
echo " </div>";
?>
My js is called funcionesNacimientos.js, and my directory is like this我的js叫funcionesNacimientos.js,我的目录是这样的
this is the body tag这是身体标签
You have to refer to the relative path, and fix the quotes problem by escape them in style='background-image: url('imagen3.jpg')'
, so it should be :你必须参考相对路径,并通过在
style='background-image: url('imagen3.jpg')'
转义来解决引号问题,所以它应该是:
..."<body style='background-image: url(\'js/img/imagen3.jpg\')'>"...
You could also try background
attribute :您也可以尝试
background
属性:
..."<body background='js/img/imagen3.jpg'>"...
Hope this helps.希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.