zoukankan      html  css  js  c++  java
  • nodejs不同浏览器跳转问题

    前提:配置好简单的nodejs和bootstrap的服务,让用户可以通过localhost:8001和localhost:8001/index.html都可以访问

     1             fs.readFile("."+request.url,'utf-8',function(err,data)
     2             {
     3                 if(err)
     4                 {
     5                     throw err;
     6                 }
     7                 response.writeHead(200,{"Content-Type":{
     8                     ".html":"text/type",
     9                     ".css":"text/css",
    10                     ".js" :"application/javascript"
    11                 }
    12                 });
    13                 response.write(data);
    14                 response.end();
    15             })
    16         

    火狐:两个入口都可以访问,样式也正常加载了。

    ie:localhost:8001/index.html可以正常访问,localhost:8001是下载index.html页面

    chrome:两个入口都可以访问,但样式加载不了

    解决办法:

     switch (ext)
        {
            case ".css":
            case ".js":
                fs.readFile("."+request.url,'utf-8',function(err,data){
                    if(err)
                    {
                        throw err;
                    }
                    response.writeHead(200,{"Content-Type":{
                        ".css":"text/css",
                        ".js" :"application/javascript"
                    }[ext]
                    });
                    response.write(data);
                    response.end();
                })
                break;
            default :
              fs.readFile("./index.html","utf-8",function(err,data)
                    {
                        if(err) throw err;
                        response.writeHead(200,{"Content-Type":"text/html"});
                        response.write(data);
                        response.end();
                    });
    }
      
  • 相关阅读:
    2018 ACM 网络选拔赛 徐州赛区
    2018 ACM 网络选拔赛 焦作赛区
    2018 ACM 网络选拔赛 沈阳赛区
    poj 2289 网络流 and 二分查找
    poj 2446 二分图最大匹配
    poj 1469 二分图最大匹配
    poj 3249 拓扑排序 and 动态规划
    poj 3687 拓扑排序
    poj 2585 拓扑排序
    poj 1094 拓扑排序
  • 原文地址:https://www.cnblogs.com/hellowoody/p/3961956.html
Copyright © 2011-2022 走看看