Using MathML and JavaScript inside WebBrowser component - c#

I have the following webpage in HTML using MathML. In my Firefox, this displays a nice mathematical equation $a x^2 + b x + c$, as MathML should.
I figured I could now load this webpage into the WebBrowser of my Visual Studio 2015 WPF Application. However, the MathML does not render as expected. I suppose the WebBrowser component is not capable of dealing with MathML.
I have a second webpage using JavaScript, which I need for similar reasons. This, too, works in Firefox but not inside the WebBrowser of Visual Studio.
Any suggestions?
<html>
<head>
<title>
Title
</title>
</head>
<body>
MathML:
<br>
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<mi>a</mi>
<mo>&InvisibleTimes;</mo>
<msup>
<mi>x</mi>
<mn>2</mn>
</msup>
<mo>+</mo>
<mi>b</mi>
<mo>&InvisibleTimes; </mo>
<mi>x</mi>
<mo>+</mo>
<mi>c</mi>
</mrow>
</math>
</body>
</html>

MathML is not yet supported by the WebBrowser in Visual Studio (probably IE). Math can be typeset using CSS and javascript. A webpage would then need to include
<!-- saved from url=(0014)about:internet -->
in order not to get the pop-up "Allow blocked content".

Related

Porting HTML 5 page to a webBrowser object in winforms

I'm trying to port THIS pasge and its HTML5 animation to a winform.
What I did is copied and added the index.html and all the css and js file to my project. This is how my project directory looks like
And then I'm trying to load the html file into my webbrowser object using this code snippet
private void Form1_Load(object sender, EventArgs e)
{
string curDir = Directory.GetCurrentDirectory();
this.webBrowser2.Url = new Uri(String.Format("file:///{0}/index.html", curDir));
}
And I have set properties of all the file to Copy Always
Now when I run the project I get a script error message and upon pressing Yes
it loads the page but only background is displayed and the animation is lost!
please help!
PS: I've changed
<link href="css/main.css" rel="stylesheet" type="text/css" />
<script src="js/ThreeWebGL.js"></script>
<script src="js/ThreeExtras.js"></script>
To
<link href="main.css" rel="stylesheet" type="text/css" />
<script src="ThreeWebGL.js"></script>
<script src="ThreeExtras.js"></script>
in index.html file
Screenshots of two script error that I'm getting--
It works in IE10
The *.js files need to be in a js folder. Either create the folder and move them or edit the html file.
EDIT1:
Does it work if you point it to "http://www.script-tutorials.com/demos/177/index.html"?
EDIT2:
Add:
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
in the html head section.
EDIT3:
I tried on my machine and it's the same behavior. But the page does run fine in Internet Explorer 11. Maybe the WinForms control uses IE engine in some compatibility mode.
I would use http://www.awesomium.com/
The webbrowser control is just an instance of IE - that page doesn't work for me in Internet Explorer so it's unlikely to work in the embedded browser. Search for webkit net - might give you better results. I'm tempted to ask why you want to do this but I'm sure you've got a good reason.
Got it working! Basically the set up works fine. Just had to open main.css file and comment out all the footer properties to get rid of the footer and found another script ref which was pointed to js/script.js had to change it to script.js
Now how can i increase the framerate so that it doesnt stutter? Theres a lag at the moment

Html Image size when added via Microsoft.Office.Interop.Outlook

Using MS outlook 2010, c# in Visual Studio 2012, Microsoft.Office.Interop.Outlook version 14.
I'm trying to use outlook automation to open a new email, pre-populated with some html.
Here's the code:
using Microsoft.Office.Interop.Outlook;
using Outlook = Microsoft.Office.Interop.Outlook;
...
// bring up outlook
Application oApp = new Application();
Outlook._MailItem oMailItem = (Outlook._MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
oMailItem.To = "any#any.com";
string body = System.IO.File.ReadAllText("welcome.html");
oMailItem.HTMLBody = body;
oMailItem.Subject = "Welcome";
oMailItem.Display(false);
Where welcome.html looks like this:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Welcome</title>
</head>
<body lang="EN-AU">
<p>hello world</p> <!-- XXX : repeat as necessary -->
<p>
<img src="http://www.w3.org/2008/site/images/logo-w3c-mobile-lg" alt="logo" />
</p>
</body>
</html>
Note: any logo (which is not too small) can be used - the one I have used is just an example.
The code works ok, but there is a problem with the logo size.
The problem can occur when the html line marked at XXX is repeated many times, (say 50).
There are two cases:
a) in outlook, before you send the email, scroll down to view the complete document. I noticed that outlook seems to resize the image. When the email is sent, the receiver sees the image in normal size:
b) in outlook, before you send the email, DO NOT scroll down to view the complete document. When the email is received, the image is small. (32 pixels by 32 pixels):
The email resulting from case a) is the desired outcome. But it would be better if the user didn't have to scroll down to preview the whole thing before sending.
Any workarounds ? Using html width and height attributes on img to explicitly set the dimensions seems to work, but this is not desirable because in real life, the image is dynamically selected (so that the size can't be hardcoded). If there was some way (via automation) to simulate previewing the whole email before sending, this might work as well.
Moe,
Outlook uses Word as an email editor. You can read about supported and unsupported HTML elements, attributes, and cascading style sheets properties in the following series of articles in MSDN:
Word 2007 HTML and CSS Rendering Capabilities in Outlook 2007 (Part 1 of 2)
Word 2007 HTML and CSS Rendering Capabilities in Outlook 2007 (Part 2 of 2)

Click on dynamically generated element after body onload using Selenium

I'll do my best to convey my situation as the date I can give you is limited.
There is this button inside a webpage when clicked creates a new tab whose HTML source is somewhat like below.
<HTML><HEAD><META content="IE=5.0000" http-equiv="X-UA-Compatible">
<TITLE>Report Viewer Webpage</TITLE>
<META content="text/html; charset=windows-1252" http-equiv=Content-Type>
<SCRIPT src="javascript1.js"></SCRIPT>
<SCRIPT src="javascript2.js"></SCRIPT>
<SCRIPT src="anotherJavascript.js"></SCRIPT>
</HEAD>
<BODY onload="CallInit('ABC_DEFG_HIJKL_1_',''); window_onload();" onhelp=common_ShowHelp() leftMargin=0 topMargin=0 bgColor=#c6c6c6 currJsHelpVar="help_reports_viewer_dlg">
<OBJECT id=CRViewer codeBase="/viewer/activeXViewer/activexviewer.cab#Version=9,2,0,442" classid=CLSID:1123452WDUIHED:1325726GDUJBEA:12R432VD width="100%" height="99%" VIEWASTEXT>
<PARAM NAME="lastProp" VALUE="500">
<!--Bunch of other params go here-->
<PARAM NAME="_cx" VALUE="26987">
<SCRIPT language=VBScript>
<!--Some Business Logic-->
</SCRIPT>
<OBJECT id=ReportSource codeBase="/viewer/activeXViewer/activexviewer.cab#Version=9,2,0,442" classid=CLSID:1123452WDUIHED:1325726GDUJBEA:12R432VD width="1%" height="1%"></OBJECT>
<OBJECT id=ViewHelp codeBase="/viewer/activeXViewer/activexviewer.cab#Version=9,2,0,442" classid=CLSID:1123452WDUIHED:1325726GDUJBEA:12R432VD width="1%" height="1%"></OBJECT>
</BODY>
</HTML>
And the page content look something like this:
And of course this is a Crystal Report.
All I want to do is click on the neat little Export button sitting right beside Print button above the text preview.
And I am using Selenium to automate all this. But the problem is, selenium only works with HTML elements and I believe the buttons in the page are ActiveX controls or something else. And they are only loaded after the call to <Body> tag's onLoad call.
One of the biggest constraint is that this application only works in IE and the power of IE developer tools is not enabling me to inspect the button element. IE developer tools just doesn't see those buttons as HTML elements. They don't exist to IE developer tools. I am using IE 9 by the way.
What would help me in automating the clicking of that Export button ? Any javascript would help ??
When I inspected this webpage, the first <Object> right after the <Body> is taking all the space of the view. And I think that randomly generated elements are going inside it dynamically.
You can try FluentAutomation. It is written on top of Selenium and has Click on (x, y) coordinate function. I've managed to get it working for Crystal report. Please let me know if you have any problem.
Cheers,
Given the HTML code you're showing, it seems that the content of the page is an ActiveX.
As a result, there is no way for you to do any kind of automation with Selenium as you said it yourself, Selenium only works with HTML.

how to convert part of html page into pdf using wkhtmltopdf or something else

Iam using wkhtmltopdf for html to pdf conversion of an html page using C# code and it is working absolutely perfect but i want to convert a particular part of html page to pdf like by specifying div id of that part or any similar method.How can i do this?
Please help
You can just create a new HTML page with just your div as a body:
<html>
<head><title>...</title></head>
<body>
<!-- PLACE YOUR DIV HERE -->
</body>
</html>
Since you already know how to produce a PDF from an HTML file, you know know how to produce a PDF from a DIV ;)
BUT: Of course the CSS is going to be all wonky, since the selectors won't match anymore etc. This is a problem for the general case, but I'm guessing in your specific case, you can make that work.

How to play youtube videos on windows application C#

I've created a windows application with a WebBrowser control and trying to play youtube videos.. I've installed Adobe Shockwave Player, and tried to watch video on my windows application, but it doesn't show any videos. When I hit play button the screen looks like this
My code for playing video is
StreamWriter sw = new StreamWriter("utube.html");
string PlayString = currentVideoUrl.Trim().Replace("watch?v=", "v/");
string Finalplaycode = "<embed src=" + PlayString + "&hl=en&fs=1& type=application/x-shockwave-flash allowscriptaccess=always allowfullscreen=true width=425 height=344></embed>";
sw.Write(Finalplaycode);
sw.Close();
string PathToNavigate = Directory.GetParent(Application.ExecutablePath) + #"\utube.html";
webBrowser1.Navigate(PathToNavigate);
and my example video link is : http://www.youtube.com/watch?v=oZdnezj9Dfg&feature=BFa&list=PLD3E900BFF6534896&lf=plpp_video
can anyone help me about this issue? Did I missing any plug-in or something? I am using .NetFramework 4.0
One problem I see is that you're not quoting the parameters in the embed. Your embed will generate as:
<embed src=http://www.youtube.com/v/video_id...>
You need to quote those parameters:
<embed src="http://www.youtube.com/v/video_id...">
For example, here's an embed that works on my site:
<embed type="application/x-shockwave-flash" width="425" height="344"
src="http://www.youtube.com/v/UejelYnVI3U&hl=en&fs=1"></embed>
You might be interested in reading the official YouTube documentation. They've moved away from using embeds, in favor of iframes. That lets them use the HTML5 video player if it's available, or otherwise fall back to Flash. See http://www.google.com/support/youtube/bin/answer.py?answer=171780 for details.
Update:
The HTML file below embeds the same video in two ways: once using the iframe and once using the standard embed. It works find when I navigate to it with the WebBrowser control:
<html>
<body>
<iframe class="youtube-player" type="text/html" width="640" height="385"
src="http://www.youtube.com/embed/oZdnezj9Dfg" frameborder="0">
</iframe>
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="344"
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0">
<param name="src" value="http://www.youtube.com/v/oZdnezj9Dfg&hl=en&fs=1" />
<embed type="application/x-shockwave-flash" width="425" height="344"
src="http://www.youtube.com/v/oZdnezj9Dfg&hl=en&fs=1">
</embed>
</object>
</body>
<html>
Try copying that and navigating to it in your application. Make sure that your program is creating the embed just like that.
Also, you can remove the outer <object> tag if you already have Flash installed. Then, the Flash embed looks just like what I showed originally.
And, there's no requirement that you have the HTML wrapper around it. It works fine if I just include the embed without the <html> and other tags.

Categories