Code
<script type="text/javascript" language="javascript">
function DrawImage(ImgD)
{
var imgWidth = ImgD.width;
var imgHeight = ImgD.height;
if (ImgD.width > 830)
{
//ImgD.onclick = viewBigImg(ImgD);
ImgD.width = 830;
ImgD.height = (ImgD.height * 830) / ImgD.width;
ImgD.title = "点击查看大图";
ImgD.style.cursor = "pointer";
ImgD.setAttribute('onclick', document.all ? eval(function() { viewBigImg(this, imgWidth, imgHeight) }) : 'javascript:viewBigImg(this,'+imgWidth+','+imgHeight+')');
}
}
function viewBigImg(obj, imgWidth, imgHeight) {
var iframe = document.getElementById("transbox");
iframe.style.display = "";
iframe.style.height = document.body.scrollHeight + "px";
iframe.style.width = document.body.clientWidth + "px";
var showImg = document.getElementById("showImgImg");
showImg.src = obj.src;
showImg.style.display = "";
showImg.style.left = (document.body.clientWidth / 2 - imgWidth / 2) + "px";
showImg.style.top = document.documentElement.scrollTop + document.documentElement.clientHeight / 2 - imgHeight / 2 + "px";
return false;
}
function hideImgImg() {
var iframe = document.getElementById("transbox");
iframe.style.display = "none";
var showImg = document.getElementById("showImgImg");
showImg.style.display = "none";
}
</script>
<div id="transbox" style="display:none;position:absolute; margin:0px;left:0px; top:0px;margin: 0 0px;background-color: #000;border: 2px solid black;filter:alpha(opacity=80);opacity: 0.8;-moz-opacity:0.8;"></div><img id="showImgImg" src="" onclick="hideImgImg();" title="单击关闭" style="display:none;position:absolute;filter:alpha(opacity=100);opacity: 1;-moz-opacity:1;z-index:100;"/>
<script type="text/javascript" language="javascript">
function DrawImage(ImgD)
{
var imgWidth = ImgD.width;
var imgHeight = ImgD.height;
if (ImgD.width > 830)
{
//ImgD.onclick = viewBigImg(ImgD);
ImgD.width = 830;
ImgD.height = (ImgD.height * 830) / ImgD.width;
ImgD.title = "点击查看大图";
ImgD.style.cursor = "pointer";
ImgD.setAttribute('onclick', document.all ? eval(function() { viewBigImg(this, imgWidth, imgHeight) }) : 'javascript:viewBigImg(this,'+imgWidth+','+imgHeight+')');
}
}
function viewBigImg(obj, imgWidth, imgHeight) {
var iframe = document.getElementById("transbox");
iframe.style.display = "";
iframe.style.height = document.body.scrollHeight + "px";
iframe.style.width = document.body.clientWidth + "px";
var showImg = document.getElementById("showImgImg");
showImg.src = obj.src;
showImg.style.display = "";
showImg.style.left = (document.body.clientWidth / 2 - imgWidth / 2) + "px";
showImg.style.top = document.documentElement.scrollTop + document.documentElement.clientHeight / 2 - imgHeight / 2 + "px";
return false;
}
function hideImgImg() {
var iframe = document.getElementById("transbox");
iframe.style.display = "none";
var showImg = document.getElementById("showImgImg");
showImg.style.display = "none";
}
</script>
<div id="transbox" style="display:none;position:absolute; margin:0px;left:0px; top:0px;margin: 0 0px;background-color: #000;border: 2px solid black;filter:alpha(opacity=80);opacity: 0.8;-moz-opacity:0.8;"></div><img id="showImgImg" src="" onclick="hideImgImg();" title="单击关闭" style="display:none;position:absolute;filter:alpha(opacity=100);opacity: 1;-moz-opacity:1;z-index:100;"/>
Code
string allText = dr["contents"].ToString();
allText = Regex.Replace(allText, @"<img(?=.*?src=(['""])(?<content>[^""]*)\1)\s+(?:\w+=""[^""]*""\s*)*[^>]*>(?:</img>)?", @"<img src=""${content}"" onload=""javascript:DrawImage(this);"" border=""0"">", RegexOptions.IgnoreCase);//" onclick=""return viewBigImg(this);"" style=""cursor: pointer;"
string allText = dr["contents"].ToString();
allText = Regex.Replace(allText, @"<img(?=.*?src=(['""])(?<content>[^""]*)\1)\s+(?:\w+=""[^""]*""\s*)*[^>]*>(?:</img>)?", @"<img src=""${content}"" onload=""javascript:DrawImage(this);"" border=""0"">", RegexOptions.IgnoreCase);//" onclick=""return viewBigImg(this);"" style=""cursor: pointer;"