![]() ![]() Content settings, like letting a site show you pop-ups or use your microphone.Learn how to set the page that a new tab opens to. Learn how to set your Chrome homepage and set default startup tabs. Learn how to set your default search engine. Default search engine, which is changed back to Google.On your Chrome profile, the following settings will change to the default on all devices where you're signed in: What changes when you restore your settings To create a new user profile, add a new user in Chrome. For example, some settings like fonts or accessibility won't be deleted. Select Reset settings Restore settings to their original defaults Reset settings.At the top right, select More Settings.Render_template method via flask or to say, using flask as your web server. Note: This works only if you are rendering your HTML file using the So to serve this get request, we wrote an endpoint that takes the audio file name, reads it from the local directory, and returns it back. When you give the audio file name under src property, this creates a get request in the flask as shown 127.0.0.1 - "GET /Std.mp3 HTTP/1.1" 200 -Īs you can see that, the flask has sent a Get request for the Std.mp3 file. Path_to_audio_file = "C:/Audios/yourFolderPath" + audio_file_name In case you are trying to play audio with dynamic paths, by changing src property through JS, then here is a sample implementation using Flask server and HTML. This makes sense because any webpage can't simply give a local path and access your private files. In the case of audio files, when you give, this throws an error saying cannot load local resource. String myEncodedString = HttpUtility.HtmlEncode(result) Į = myEncodedString X.SetAttributeValue("src", "data:" + contenttype + " base64," + Convert.ToBase64String(bytes)) String contenttype = "image/" + Path.GetExtension(filename).Replace(".", "") įileStream fs = new FileStream(filePath + filename, FileMode.Open, FileAccess.Read) īyte bytes = br.ReadBytes((Int32)fs.Length) String filename = Path.GetFileName(currentSrcValue) String filePath = Path.GetDirectoryName(currentSrcValue) + "\\" String currentSrcValue = x.GetAttributeValue("src", null) ![]() Return !string.IsNullOrEmpty(src) //& src.StartsWith("data:image") String src = e.GetAttributeValue("src", null) ? "" HtmlDocument document = new HtmlDocument() find and replace each img src with byte string ![]() String DecodedHtmlString = myWriter.ToString() HttpUtility.HtmlDecode(encodedHtmlString, myWriter) StringWriter myWriter = new StringWriter() It will definitely display all images with network path(or local path) in IE,chrome and firefox. You just need to replace all image network paths to byte strings in stored Encoded HTML string.įor this you required HtmlAgilityPack to convert Html string to Html document.įind Below code to convert each image src network path(or local path) to byte sting. So the best you can do is use code like mine to access files somewhere on a network drive. Your website will sit on one server (with it's own C: drive) and has no direct access to your user's own C: drive. Just one last comment: the original question wanted to open the file " C:\002.jpg". but I'm posting this code just to demonstrate that this is a fairly simple way around this limitation. Phew ! Again - there is a reason why Chrome throws this " Not allowed to load local resources" exception, so tread carefully with this. This Handler code loads the file, then passes it's contents back in the HTTP response.Īnd, job done, the webpage opens the external file. ashx file, passing it the path+filename of the file we want to open. Now, when a user clicks on one of my Shortcut links, it calls the OpenAnExternalFile function, which opens this. $scope.OpenAnExternalFile = function (filename) ", filename)) Ĭ() ![]() The solution was to replace those elements with this code, to call a function in my Angular controller. Originally, my webpage was attempting to directly create an element pointing at the files, but this produced the " Not allowed to load local resource" error when a user clicked on one of these links. This webpage uses AngularJS 1.x to list the various shortcuts. but of course, Chrome's error prevents this. When they click on one of these shortcuts, we want to open these files. Our in-house app has a webpage where users can create a list of shortcuts to useful files spread throughout our network. It uses ASP.Net (rather than JavaScript, which this question was based on) but it'll hopefully be useful to someone. Okay folks, I completely understand the security reasons behind this error message, but sometimes, we do need a workaround. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |