最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin1浏览0评论

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";
发布评论

评论列表(0)

  1. 暂无评论