• asp.net 文件路径问题,Png图片透明问题,js提示对象不支持属性和方法的解决方案


    1.asp.net 文件路径问题

    最近godaddy空间的使用中,应用到网站地图,还有cuteeditor编辑器,出现找不到路径的问题,然后就查找资料,对路径有如下的资料收集。

    Cuteeditor最开始是权限的问题,没有对upload文件夹赋予写的权限,就不停的报错,后来还要在根目录创建temp文件夹,并且赋予写的权限,因为godaddy空间的默认安全级别比较高,所以,cuteeditor没有执行权限,无奈,创建temp文件夹,添加到webconfig中,但是系统一直提示没有找到temp文件夹,后来尝试多种方式就不行,后来把路径修改为~/temp,问题解决。

    网站地图提示找不到sitemap文件,后来修改为../sitemap.

    如果有文件夹abc,和aaa.jpg文件 
    ./abc/aaa.jpg 
    ./abc\aaa.jpg 
    ../abc/aaa.jpg 
    ~/abc/aaa.jpg 
    /abc/aaa.jpg 
    http://localhost/abc/aaa.jpg 
    Server.MapPath("./abc/")+"aaa.jpg" 
    以及"//"和"\"含义!
    / 是超文本协议的路径分隔符号,所有的网站在浏览器中显示的路径分隔都是以"/"表示.它一般代表虚拟路径. 
    在普通程序代码中则以"\"表示文件路径分隔符号.它一般指物理路径. 
    ./ 表示在当前路径下, 
    ../表示在当前路径的上一级路径下. 
    ~/表示当前网站的根目录下. 
    比如有网站路径如下 
    C:\Inetpub\wwwroot\test\ 
    新闻路径如下 
    C:\Inetpub\wwwroot\test\news\ 
    C:\Inetpub\wwwroot\test\news\2008\ 
    C:\Inetpub\wwwroot\test\news\2008\info\ 

    假设每个文件夹下面有个Default.aspx 
    以C:\Inetpub\wwwroot\test\news\2008\Default.apsx为例: 
    调试时显示路径为 
    http://localhost/test/news/2008/default.aspx
     反斜杠都是虚拟路径分隔,它不会显示C:\Inetpub\wwwroot这节物理路径. 
    ~/Default.aspx 指向C:\Inetpub\wwwroot\test\Default.aspx 
    显示Http://localhost/test/default.aspx 
    ../Default.aspx 指向C:\Inetpub\wwwroot\test\news\Default.aspx(两点表示当前文件的上一级目录) 
    显示Http://localhost/test/news/default.aspx 
    /info/Default.aspx 指向C:\Inetpub\wwwroot\test\news\2008\info\Default.aspx 
    显示Http://localhost/test/news/2008/info/default.aspx
    / 是超文本协议的路径分隔符号,所有的网站在浏览器中显示的路径分隔都是以"/"表示.它一般代表虚拟路径. 
    在普通程序代码中则以"\"表示文件路径分隔符号.它一般指物理路径. 
    ./ 表示在当前路径下, 
    ../表示在当前路径的上一级路径下. 
    ~/表示当前网站的根目录下. 
    还有 /和\\ 是等值得的! 
    你上面所说的全叫相对路径 是根据你文件当前位置来的 

    ./指的是当前目录 
    ../指上一级目录 
    /的话,从根目录开始。 
    ~/的话,从当前项目开始(.NET 2.0新加)。 
    http://localhost/的话,连域名也包含了,当你换一个域名的话就不能访问了。 
    Server.MapPath("./abc/")+"aaa.jpg"得到的是在当前服务器上的物理路径。 另外,如果你需要的导向对于当前页面的路径。用Control.ResolveUrl(string relativeUrl)方法,另外还有Control.ResolveClientUrl(string relativeUrl)方法。

     

    2.Png图片透明解决方案

    1.Ie6png图片显示很难看,现在网站的首页多个产品,设计都用的png图片,没有办法,只好通过js实现解决透明图片的问题。 

    网上找了一下,有多重方法,我这里用的是如下的方法:

     

    View Code
     1 <script language="JavaScript"> 
     2          function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6. 
     3          {
     4              var arVersion = navigator.appVersion.split("MSIE")
     5              var version = parseFloat(arVersion[1])
     6              if ((version >= 5.5&& (document.body.filters)) {
     7                  for (var j = 0; j < document.images.length; j++) {
     8                      var img = document.images[j]
     9                      var imgName = img.src.toUpperCase()
    10                      if (imgName.substring(imgName.length - 3, imgName.length) == "PNG") {
    11                          var imgID = (img.id) ? "id='" + img.id + "" : ""
    12                          var imgClass = (img.className) ? "class='" + img.className + "" : ""
    13                          var imgTitle = (img.title) ? "title='" + img.title + "" : "title='" + img.alt + ""
    14                          var imgStyle = "display:inline-block;" + img.style.cssText
    15                          if (img.align == "left") imgStyle = "float:left;" + imgStyle
    16                          if (img.align == "right") imgStyle = "float:right;" + imgStyle
    17                          if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
    18                          var strNewHTML = "<span " + imgID + imgClass + imgTitle
    19              + " style=\"" + "" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
    20              + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
    21              + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
    22                          img.outerHTML = strNewHTML
    23                          j = j - 1
    24                      }
    25                  }
    26              }
    27          }
    28          window.attachEvent("onload", correctPNG); 
    29 </script>

    发现的另外一种不错的方法。.使PNG图片格式在IE6中背景透明(pngfix)  

    GIF(Graphics Interchange Format图像互换格式)可实现图像区域的部分或全局透明。现非常多的网站都将其运用到其中。
    但是256色的限制GIF的使用范围。还有一个问题:譬如,当我们的图像边缘有阴影时,保存透明后会发现其边缘不是以渐变式透明显示,而是用灰度色显示而无透明而言。

    解决上面GIF的缺陷方案最好方法就是使用现在网络上流行使用的另一种图像格式PNG(Portable Network Graphic Format流式网络图形格式)
    但是PNG最大的问题就是,它在IE6下无法显示透明区域(Firefox、Opera、Safari均支持PNG透明),会有一种灰白色代替成为其背景色。这不是PNG这个格式图片的问题,而是IE6的BUG,没有将PNG的Alpha通道打开,造成透明PNG图片的在IE6上显示不出透明区域。

    现在就有种方法是通过引入JavaScript的方式解决这个问题。



    var arVersion = navigator.appVersion.split("MSIE");
    var version = parseFloat(arVersion[1]);
    var pngxp=/\.png$/i;
    var AlphaPNGfix= "progid:DXImageTransform.Microsoft.AlphaImageLoader";
    function fixPNGAll() {
            if(!document.all) return;
            if ((version >= 5.5 && version < 7) && (document.body.filters)) {
              for(var i=0; i<document.images.length; i++) {
                    var img = document.images[i];
                    if(img.src && pngxp.test(img.src)) {
                      var imgName = img.src;
                      var imgID = (img.id) ? "id='" + img.id + "' " : "";
                      var imgClass = (img.className) ? "class='" + img.className + "' " : "";
                      var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
                      var imgStyle = "display:inline-block;" + img.style.cssText;
                      if (img.align == "left") imgStyle = "float:left;" + imgStyle;
                      if (img.align == "right") imgStyle = "float:right;" + imgStyle;
                      if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle;
                      var strNewHTML = "<span " + imgID + imgClass + imgTitle
                      + " style=\"" + "" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
                      + "filter:" +AlphaPNGfix
                      + "(src='" + img.src + "', sizingMethod='scale');\"></span>";
                      if (img.useMap) {
                            strNewHTML += "<img style=\"position:relative; left:-" + img.width + "px;"
                            + "height:" + img.height + "px;" + img.width +"\" "
                            + "src=\"" + PIXELGIF + "\" usemap=\"" + img.useMap
                            + "\" border=\"" + img.border + "\">";
                      }
                      img.outerHTML = strNewHTML;
                      i--;
                    }
              }
              /* for type=image png button */
              var kmax = document.forms.length;
              for(var k=0; k<kmax; k++) {
                    var fmob = document.forms[k];
                    var elmarr = fmob.getElementsByTagName("input");
                    var jmax = elmarr.length;
                    for(var j=0; j<jmax; j++) {
                            var elmob = elmarr[j];
                            if(elmob && elmob.type=="image" && pngxp.test(elmob.src)) {
                                    var origsrc = elmob.src;
                                    elmob.src = PIXELGIF;
                                    elmob.style.filter = AlphaPNGfix+"(src='" +origsrc +"')";
                            }
                    }
              }
            }
    }

    function fixPNG(img) {
            if(!document.all) return;
            var img;
        if(img && img.src && pngxp.test(img.src)) {
          var imgName = img.src;
          var imgID = (img.id) ? "id='" + img.id + "' " : "";
          var imgClass = (img.className) ? "class='" + img.className + "' " : "";
          var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
          var imgStyle = "display:inline-block;" + img.style.cssText;
          if (img.align == "left") imgStyle = "float:left;" + imgStyle;
          if (img.align == "right") imgStyle = "float:right;" + imgStyle;
          if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle;
          var strNewHTML = "<span " + imgID + imgClass + imgTitle
          + " style=\"" + "" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
          + "filter:" +AlphaPNGfix
          + "(src='" + img.src + "', sizingMethod='scale');\"></span>";
          if (img.useMap) {
            strNewHTML += "<img style=\"position:relative; left:-" + img.width + "px;"
            + "height:" + img.height + "px;" + img.width +"\" "
            + "src=\"" + PIXELGIF + "\" usemap=\"" + img.useMap
            + "\" border=\"" + img.border + "\">";
          }
          img.outerHTML = strNewHTML;
        }
    }


    第二步:
    在head标签中引入js文件



    第三步(分两种情况):
    1、指定PNG图片使其在IE6下背景透明
    在img标签中加入onload="fixPNG(this)"事件


    2、页面内所有PNG图片使其在IE6下背景透明
    在body表情中加入onload="fixPNGAll()"事件



    需要注意的是:
    如果你的网页需要符合XHTML 1.0标准的话,请用第三步中的2方法,因为1方法中img标签中的onload事件是不符合XHTML 1.0标准的

    特殊情况(用PNG为button按钮的背景时):
    如果你要在input标签的背景中使用PNG图片,此js文件同样适用。

    先在head标签中引入js文件



    在body标签中加入onload="fixPNGAll()"事件

     

     

     

    3.IE提示对象不支持属性和方法的解决方案

    feellife.com网站发布后,在contactus.html页面中,有一个滚动图片的效果,然后页面底部引用了网站访问量统计的功能,两个js文件,页面提示对象不支持属性和方法的js错误,后来才知道原来id冲突拉,在滚动中用到idb1的值,而在计数的js中,同样用到idb1js,后来修改计数的js,问题解决。

  • 相关阅读:
    trailRenderer
    通过sysobjects快速查找SQLServer中是否有某个表、视图、存储过程等对象实操
    浅谈信息系统(IT)项目管理-序幕
    使用open xml 判断sharepoint文档是否损坏
    Sharepoint the file is locked for use domainuser edit.文件被锁定,解锁方式
    sharepoint 列表库指定序号规则
    Biztalk 宏
    Biztalk 在流程中定义将消息保存为文件的文件名
    Biztalk 2013 新特性简介(英)
    devexpress gridview,selectedrowchanged
  • 原文地址:https://www.cnblogs.com/gxg2008540/p/2090039.html
Copyright © 2020-2023  润新知