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();
                    });
    }
      
  • 相关阅读:
    cf 1155 d 最大区间和(变形 区间*x)
    俄罗斯方块的形状暴力
    cf 1160 E dp 组合数 思维
    cf 1110d dp(题目特殊性质)
    cf 1114d 区间dp 0,1标记左右
    poj 1426 bfs
    poj 1679 最小生成树是否唯一
    cf 1106e dp
    【PAT顶级】1002 Business (35分)(0/1背包,DP)
    【PAT顶级】1001 Battle Over Cities
  • 原文地址:https://www.cnblogs.com/hellowoody/p/3961956.html
Copyright © 2011-2022 走看看