2013-06-18 86 views
1

我有一個包含圖像的彈出窗口。我想知道是否可以爲我的圖片設置大小。我爲彈出窗口創建了此腳本:將圖像調整爲彈出窗口

function open_win(title, description, src, alt) 
{ 
    var img = document.createElement("img"); 
    img.src = src; 
    img.alt = alt; 

    myWindow = window.open('', '', 'width=300, height=300, left=700, top=400') 
    myWindow.document.write("<div class='description'> <img src=" + src + " alt=" + alt + " >") 
    myWindow.document.write("<h4>" + title + "</h4>") 
    myWindow.document.write("<p>" + description + "</p></div>") 

    document.body.appendChild(img) 

    myWindow.focus() 
} 

我想讓我的照片成爲1185x785。我已經搜索瞭如何做到這一點,但我只是在調整窗口大小的答案,我不需要。我只是想調整我的形象。謝謝! 我試過這個,但它不起作用:

img.style.width='1185px'; 
img.style.height='785px'; 

回答

1

我找到了答案! 我只需要改變這一行:

myWindow.document.write("<div class='description'> <img src=" + src + " alt=" + alt + " >") 

與這一個

myWindow.document.write("<div class='description'> <img src=" + src + " alt=" + alt + " width=1185 height=785 >")