Not allowed to load local resource: file

前端 未结 3 1629
南笙
南笙 2020-12-11 15:05

I am using the code below to create a link, when I click on the link in IE it\'s working and I\'m able to open the URL but not in Chrome.

Test

        
相关标签:
3条回答
  • 2020-12-11 15:47

    For anyone landing here and working in asp.net:

    I was having the same issue (not allowed to load local resource) in every browser except IE.

    My workaround was to have the anchor direct to a handler & include a query string for the path:

    <a href='handler.ashx?file=//server_name//dir//filename.pdf' />
    

    Then the handler would write the file as the response (opens up in a new tab as desired with _self):

    public void ProcessRequest (HttpContext context) {
    
            if (context.Request["file"] != null && !String.IsNullOrEmpty(context.Request["file"].ToString()))
            {
                try
                {
                    context.Response.Clear();
                    context.Response.ClearContent();
                    context.Response.ClearHeaders();
                    //whichever content type you're working with
                    context.Response.ContentType = "application/pdf";
    
                    //encode the path when you set the href of the anchor, so decode it now
                    string file_name = HttpUtility.UrlDecode(context.Request["file"].ToString());
                    context.Response.TransmitFile(file_name);
    
                }
                catch { }
            }
    }
    
    0 讨论(0)
  • 2020-12-11 15:49

    I have tried this in IE, Chrome and Firefox. It's working.

    <a href='#'onClick=window.open('displayData.html','_self') >Test</a>
    

    I am not sure, but it may be possible that your browser version affects it. Please update your browser version then try again.

    0 讨论(0)
  • 2020-12-11 15:54

    When you try to open a file with FILE:\\\\ via javascript in IE. IE will not allow you to open it (which is a by default behaviour) because of some security restrictions. I have faced this IE security issue before in multiple projects. You can try changing IE security settings as given below, but its not recommended (since you cannot change each and every User's setting to change the behaviour).

    Following settings works for IE 8

    In Internet Explorer, go to Tools → Internet Options → Advanced. Scroll down to the Security section and check the box for "Allow active content to run on files on My Computer".

    0 讨论(0)
提交回复
热议问题