如何将参数放在windows.open中的函数中?

时间:2014-03-25 17:28:20

标签: javascript html

我做了一个非常简单的功能,打开了我调整的特定宽度和高度的窗口。 我的问题是下一个:你怎么能把我的宽度和高度参数放在我的windows.open中?我只想调用函数并调用参数来获得精确的测量值。因为我可能会有3-4个不同的窗口以不同的尺寸打开......

JAVASCRIPT

function ouvrirFenetre(width,height){
    window.open('formulaire.php','mywin','left=20,top=20,width='width',height='height'');
}

HTML

<a href="#" onclick="ouvrirFenetre(300,200);">My link</a>

1 个答案:

答案 0 :(得分:2)

您必须使用+符号将字符串与变量连接起来。试试:

function ouvrirFenetre(width,height){
    window.open('formulaire.php','mywin','left=20,top=20,width=' + width + ',height=' + height);
}