javascript 对话框 如何修改标题?

JavaScript06

javascript 对话框 如何修改标题?,第1张

用showModalDialog()弹出对话框。

例子如下:

1、A.html:执行弹出对话框

<script>

showModalDialog("B.html","","dialogWidth:250pxdialogHeight:200pxcenter:yeshelp:noresizable:yesstatus:no")

</script>

2、B.html:弹出对话框需要显示的内容

<html>

<title>弹出对话框标题</title>

<body>

<p>对话框内容</p>

</body>

</html>

思路:使用document.title获取页面标题,使用value属性为文本框赋值,关键代码:

document.getElementById(input_id).value=document.title

实例演示如下:

1、HTML结构

<html>

<head>

    <title>TEST</title>

</head>

<body>

    <input type="text" id="test"/>

    <input type='button' value='点击按钮获取页面标题' onclick="fun()"/>

</body>

2、javascript代码

function fun(){

var title = document.title

document.getElementById("test").value = title

}

3、效果演示

<script>

for(var i=1i<=6i++)

document.write("<h"+i+">示例文字标题"+"</h"+i+"><br />")

</script>