google reader 的 prompt 函数

本文介绍了一种针对Internet Explorer 7浏览器中prompt功能受限的情况下的替代实现方法。通过判断浏览器类型并使用showModalDialog来创建一个自定义的输入框,解决了IE7下无法正常使用prompt的问题。
[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]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值