javascript - In html, open a new window with selected background color - Stack Overflow

the html page contains 3 radio buttons- red,green, blue.If we selected any one of radio button, onw new

the html page contains 3 radio buttons- red,green, blue.If we selected any one of radio button, onw new window has to open, and that window background color should be the selected radion button color. can anyone help me how to solve this..

the html page contains 3 radio buttons- red,green, blue.If we selected any one of radio button, onw new window has to open, and that window background color should be the selected radion button color. can anyone help me how to solve this..

Share Improve this question asked Jul 4, 2012 at 11:43 harikaharika 331 gold badge2 silver badges7 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 1

Try this (demo on jsbin., you might need to allow popups):

HTML:

<label for="red">Red</label>
<input type="radio" id="red" name="windowcolor" data-color="red" />
<label for="green">Green</label>
<input type="radio" id="green" name="windowcolor" data-color="green" />
<label for="blue">Blue</label>
<input type="radio" id="blue" name="windowcolor" data-color="blue" />

JavaScript:

function openWindowWithColor() {
  var color = this.getAttribute("data-color");
  console.debug("Open new window with color: " + color);
  var myNewWindow = window.open();
  myNewWindow.document.body.style.background = color;
} 

var radios = document.getElementsByTagName("input");

for(var i = 0; i < radios.length; i++) {
  radios[i].addEventListener("change", openWindowWithColor);
}
<script>
    function open(var color){
        //window.open("new_page.html#"+color);
        var myNewWindow = window.open("url");
        myNewWindow.document.body.style.background = color;
    }
</script>

<input type="radio" onclick="open('red')" />
<input type="radio" onclick="open('green')" />
<input type="radio" onclick="open('blue')" />
var newwindow = window.open('popup.aspx','Color Popup','height=400,width=200');
newwindow.document.body.style.background = "#000";

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745626884a4636861.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信