WPF WebBrowser won't show Google Maps - c#

This is a follow up question to this question:
Load local HTML file in a C# WebBrowser
I've created an html file by simply copying the example from this link:
https://developers.google.com/maps/documentation/javascript/examples/marker-simple
When I run it by double clicking the file which opens the regular web browser (i.e Firefox), it works. I then added the HTML to my sln, and change the file's property to always be copied to the output directory. I then tried running it like this:
string curDir = Directory.GetCurrentDirectory();
webBrowser.Navigate(new Uri(String.Format("file:\\{0}\\mymap.html", curDir)));
The browser is opened with the yellow warning on top:
"to help protect your security, your browser has restricted this file from showing active content .."
I'm clicking it, allowing the blocked content, and then I get a message saying there's an error in the script in the page. I'm allowing it to continue, and the browser remains blank.. why is that?

After searching for an answer, I came across this blog entry:
https://weblog.west-wind.com/posts/2011/May/21/Web-Browser-Control-Specifying-the-IE-Version
First of all for the yellow warning, just add this comment line under the html tag of the page:
<!-- saved from url=(0016)http://localhost -->
You can read more about it here:
https://learn.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/compatibility/ms537628(v=vs.85)
Regarding the map and the script error:
It seems like you need to set the WebBrowser's IE version to edge, in order to be able to render HTML5.
set this line as the first one inside the head tag:
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
After these 2 changes, it will work

Related

Check if PDF viewer plugin is installed in IE/Chrome/FireFox/Safari

I am trying to create function that will essentially check if there is any PDF Viewer [Adobe or any other] is installed as Plugin for browser.
For example:
I someone click on link in webpage it will open up the PDF file instead of showing option to download, this means a PDF viewer plugin is present in browser.
I have my help on internet for this but none of them is with C# code.
Most of them is either JavaScript to check the plugins
others are there to check if Adobe PDF viewer is installed on the machine.
As a pure C# solution, I am not sure where you would want to run it, how would you go about using C# on a browser unless you are working server side? you can try the below as soon as you load your browser page and just save the details to the session variable if asp.net, then you always have a reference to the status of weather the plugin is installed or not.
You cant try a few ways to solve the issue, the first and simplest would be to just create a simple object tag
<object width="400" height="400" data="helloworld.pdf">
<p>Browser does not support PDF</p>
</object>
You can render this on a different page and just query if the control comes up or if the Browser does not support PDF message is shown,might as well just hide it, render it and then check it.
Or you could use the NavigatorPlugins that you can go through and find if there is anything related to PDF
You can check a reference to this SO answer

Layout Page not rendering Some Pages Asp.net MVC5

i am trying to develop MVC5 applicaiton. i am facing a problem. i have set a layout page placed in shared folder. Home pages of all controls are working properly.
but other pages are not showing in proper way.
I have attached a sample page Details
I checked css is also showing in source but page is not displaying in proper way
Thanks in advance. i am new in MVC
If you open your browser's Developer Toolbar and review the network tab you should be able to see if your pages are returning 404 for the files. When your browser is open press F12 and the toolbars should open.
It looks to me like your references to your local/application based stylesheets/javascript are missing the tilde symbol ~ at the beginning which means in ASP.NET the server-side application root.
For example ~/Content/bootstrap.css would be translated to the URL of the bootstrap.css file that's in the application's root.
You can drag and drop the bootstrap.css file in your content file into the _layout.cshtml file to see the correct path for the href attribute.
Put the sympole ~ before the link of css path

Not able access elements inside frames in IE, but works fine in Chrome and FireFox

I am using Selenium webdriver to automate a web application, that has many frames.
The elements inside frame are not getting identified when I run my scripts in IE,and I get an exception "Unable to find element with link text == testing". But this works perfectly in Chrome and Firefox.
I went through many related discussion, and tried the following work arounds, but they dint help.
Inserted wait statement before and after switching the frame.
Disabled proxy setting for IE.
Modified IE setting to display both secure and non secure contents
Checked 'Allow active contents to run in files on my computer' check box under Internet options -> Advanced -> security in IE settings.
I use,
Selenium webdriver version 2.35.0.0
IE version: 7
Programming language: c#
Note:
The application has dynamic name and id for frames, hence I have used index for switching the frames.
I tried saving the application opened in chrome and IE as a html page. When I open the saved html page using a browser,
The one saved from chrome shows all the elements inside the frame.
The one saved from IE doesn't show any elements inside the frame.
It would be great if I get a solution to handle elements inside the frames.
Am not able to provide the full html code, but have attached the screenshot of a part of html code.
I tried saving the complete html page using Chrome and IE. And I do observe a difference in them.
This is the snapshot of html code that is saved from chrome. Here I do see "< div class="mocha" division, that has the frame.
This is the snapshot of html code that is saved from IE. Here I do not see "< div class="mocha" division, and also "< iframe > ".
I doubt, if this might be the cause for the problem. Let me know, if I had to provide more information.
The actual problem was that, for some reason identifying the frames using Index was not working properly in IE. This seems to be an issue related to application’s behavior with the IE browser. Hence we came up with the following solution to overcome this issue.
Steps:
1. Fetch all the frames in the page (using its class) as a list.
2. Iterate through the list to fetch the name of each frame in an array.
3. Then switch to the corresponding frame using frame name saved in the array.

Asp.net Mvc: why is browser looking for favicon.ico

I know there is a solution to stop the mvc framework to process "favicon.ico" requests (solution), but i don't know why is it looking for this icon in the first place.
I searched using Find in Files > Entire Solution for favicon.ico and nothing was found.
I searched in the html source code of the website for favicon.ico and nothing was found.
Where is it? why the browser is trying to serve it?
favicon.ico is a convention - but is one way that the browser can get the image for links, tabs, etc:
Note that these days, the image location can also be set in metadata (which is handy as it allows the image to be per-page rather than per-domain, and/or allows for serving it from a different location, such as a CDN):
<link rel="shortcut icon" href="//cdn.sstatic.net/stackoverflow/img/favicon.ico">
<link rel="apple-touch-icon image_src" href="//cdn.sstatic.net/stackoverflow/img/apple-touch-icon.png">
However, "/favicon.ico" is the fallback, and is used by many old browsers - or where no explicit shortcut icon is specified.
Basically: go create one.
You better have one since it is standard to most browsers to look for the favicon.ico however if you really don't want to have it and get rid of the error just add this line in your RegisterRoutes class.
routes.IgnoreRoute("{*favicon}", new { favicon = #"(.*/)?favicon.ico(/.*)?" });
Some browsers just look for favicon.ico in the root of your website by default.
I think the easiest way to stop the browser looking for this file is provide the image once, then the browser will cache it and stop asking.
The browser asks for it to set as the icon for the page, next to the title (in titlebar, tab, bookmarkmenu).

Word document from web page is downloading incorrectly

I need to generate some data on the fly (when a user clicks a button on an .aspx page) and send it to the browser as a Word document.
I found this article and copied the code. At first it worked perfectly. I made some mods to the code to get it to do what I want and suddenly I found that when IE displayed the box in which it says 'Do you want to open or save MsWordSample.doc(3.77k) from localhost' - when I click 'Open' - it shows initially '100% downloaded' but this disappears (very quickly - you barely get to read it) and is replaced by text that says 'MsWordSample.doc couldn't be downloaded'. If I click 'Retry' it opens Word but it displays a representation of the .aspx page. I.e. it shows the text box and label - it doesn't show the html which is in the Response.Write at the end of the code.
How can this happen? First off it worked fine. I have changed the page back to exactly in the sample code - but it still won't send the right data to Word - it, (after the messing around described above) opens the code on the .aspx page.
Please try something like Response.flush() and Response.End() at the end of your code.

Categories

Resources