Hi, everyone. I have a question about JavaScript.
What you want is to run the jquery script function when a new window opens, receives a value, and closes a new window. A new window opens and receives a value, and when you close the new window, it is imported by putting it in the content (text box).
If you check the value in the text box, the value will go over properly. //The value of content receives the rgb value)// So I'm going to use it to make a box with div and check the color with the background. However, if you actually take an alert or console.log in that function, it doesn't contain any value.
It's definitely in the text box, but it's not in the var content, so even if I put in the div, only the empty box comes out I don't know how to solve it. So I looked for a function that runs after the open function ends, but I haven't found it yet, and I changed the content to onchange, but it doesn't work.
Please advise me what to do.
<script>
$('#btn').on('click', function(){
var win = window.open("testpage", "testpage","left=200,width=680,height=530");
var content = $('#content').val();<---??
var con = "<div style='background-color:"+content+"width:300px; height:300px'>";
If you write the contents of //varcon as they are in jsp, it will run properly.
$("#testcol").append("<div style='background-color:"+color+"width:300px; height:300px'></div>");
<script>
//html 'jsp'
<div id="testcol">
<input type="button" id="btn" value="test button">
<input type="text" id="content" value="">
<div id="testcol">
</div>
</div>
//Function related to new window
<script>
$('#colorbtn').on('click', function(){
var c = $('.colorpreview').css('background-color');
$('#color').val(c);
opener.document.getElementById("color").value=document.getElementById("color").value;
self.close();
})
There's no particular "function that runs after the open function" you're talking about, but if you have to find it, the following code plays its role (delivering the value of the child window to the parent window).
opener.document.getElementById("color").value=document.getElementById("color").value;
I mean, in the parent's window, it's supposed to work like this, right?
var content = $('#color').val();
By the way, if you're just floating a new window to pull out a color, don't do that, but there are a variety of jquery color picker plug-ins, so choose one of them and apply it.
© 2024 OneMinuteCode. All rights reserved.