[size=large]
IE7对prompt做了限制,MS的产品部门真是好奇怪....
我抄了一下google reader的prompt实现
function ie7(){
return (document.all?true:false)&&!("contains" in document)&&!window.opera&&("XMLHttpRequest" in window);
}
function raw_input(a,b){
b=b||'';
a={_message:a,_initialValue:b,_newValue:null}
if(ie7()){
window.showModalDialog(
"/reader/ui/3744973097-zh-CN-prompt?hl=zh-CN",a,
"dialogHeight:140px;dialogWidth:400px;scroll:no;status:no;unadorned:yes"
);
return a._newValue
}else return window.prompt(a,b)
};
/reader/ui/3744973097-zh-CN-prompt?hl=zh-CN 的代码
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html><head><title>Google 阅读器</title>
<style type="text/css">
html, body {
margin: 0;
font-size: 90%;
background: #fff;
color: #000;
}
body {
padding: 1em;
}
html, body, input {
font-family: arial, sans-serif;
}
#input {
width: 100%;
}
#buttons {
text-align: right;
}
#buttons input {
width: 7em;
}
</style>
<script type="text/javascript">
function initPrompt() {
var args = window.dialogArguments;
var messageNode = document.getElementById("message");
messageNode.innerHTML = args._message;
var inputNode = document.getElementById("input");
inputNode.value = args._initialValue;
}
function handleCancel() {
window.dialogArguments._newValue = null;
window.close();
}
function handleSubmit() {
window.dialogArguments._newValue = document.getElementById("input").value;
window.close();
return false;
}
</script></head>
<body onload="initPrompt()"><form onsubmit="return handleSubmit()" action=""><p id="message"></p>
<p><input type="text" id="input"></p>
<p id="buttons"><input type="submit" value="确定">
<input type="button" onclick="handleCancel()" value="取消"></p></form></body></html>
[/size]
IE7对prompt做了限制,MS的产品部门真是好奇怪....
我抄了一下google reader的prompt实现
function ie7(){
return (document.all?true:false)&&!("contains" in document)&&!window.opera&&("XMLHttpRequest" in window);
}
function raw_input(a,b){
b=b||'';
a={_message:a,_initialValue:b,_newValue:null}
if(ie7()){
window.showModalDialog(
"/reader/ui/3744973097-zh-CN-prompt?hl=zh-CN",a,
"dialogHeight:140px;dialogWidth:400px;scroll:no;status:no;unadorned:yes"
);
return a._newValue
}else return window.prompt(a,b)
};
/reader/ui/3744973097-zh-CN-prompt?hl=zh-CN 的代码
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html><head><title>Google 阅读器</title>
<style type="text/css">
html, body {
margin: 0;
font-size: 90%;
background: #fff;
color: #000;
}
body {
padding: 1em;
}
html, body, input {
font-family: arial, sans-serif;
}
#input {
width: 100%;
}
#buttons {
text-align: right;
}
#buttons input {
width: 7em;
}
</style>
<script type="text/javascript">
function initPrompt() {
var args = window.dialogArguments;
var messageNode = document.getElementById("message");
messageNode.innerHTML = args._message;
var inputNode = document.getElementById("input");
inputNode.value = args._initialValue;
}
function handleCancel() {
window.dialogArguments._newValue = null;
window.close();
}
function handleSubmit() {
window.dialogArguments._newValue = document.getElementById("input").value;
window.close();
return false;
}
</script></head>
<body onload="initPrompt()"><form onsubmit="return handleSubmit()" action=""><p id="message"></p>
<p><input type="text" id="input"></p>
<p id="buttons"><input type="submit" value="确定">
<input type="button" onclick="handleCancel()" value="取消"></p></form></body></html>
[/size]
本文介绍了一种针对Internet Explorer 7浏览器中prompt功能受限的情况下的替代实现方法。通过判断浏览器类型并使用showModalDialog来创建一个自定义的输入框,解决了IE7下无法正常使用prompt的问题。

526

被折叠的 条评论
为什么被折叠?



