2015-10-29 2 views
1

Я пытаюсь сделать веб-страницу, где я беру вход для параметров ширины и высоты от пользователя в файле HTML. Используя JavaScript, я должен использовать введенный пользователем вход, чтобы открыть всплывающее окно настраиваемого размера. Вот код, который я написал, но он не работает.Как получить ширину и высоту пользовательского всплывающего окна от пользователя?

HTML:

<h4>5. Open pop-up window of custom size</h4> 
Height: <input type="number" id="pHeight"> 
Width: <input type="number" id="pWidth"> 
<button onclick="customPopup()">Open custom pop-up</button> 

JavaScript:

// 5. Open pop-window of custom size 
function customPopup() { 
    var h = document.getElementByID("pHeight").value; 
    var w = document.getElementByID("pWidth").value; 
    window.open ("http://google.com", "popup-custom", "status=1, scrollbars=1, width=w, height=h"); 
} 
+0

Полезно для вас. https://jsfiddle.net/g1bg5rty/1/ –

ответ

1

ваш селектор wrong.Its document.getElementById не document.getElementByID, а также вы должны пройти value of w and h не w and h as string .try код ниже:

<h4>5. Open pop-up window of custom size</h4> 
    Height: <input type="number" id="pHeight"> 
    Width: <input type="number" id="pWidth"> 
    <button onclick="customPopup()">Open custom pop-up</button> 
<script> 
function customPopup() { 

var h = document.getElementById("pHeight").value; 
var w = document.getElementById("pWidth").value; 

window.open ("http://google.com", "popup-custom", "status=1, scrollbars=1, width="+w+", height="+h); 

} 

</script>