Windows Phone 8 WebBrowser does not run javascript - javascript

I'm trying to build a WebBrowser application that targets Windows Phone 8 SDK, I had another one for WP8.1 and WebView and now i want to support earlier OS version. The thing is, the capability of executing javascript (either internal script or injected script) after WebBrowser makes a post request is impossible.
I tried posting data using 2 methods:
send a HttpWebRequest request and save result into a local html file and then tell the WebBrowser to navigate to.
simply just call Navigate(uri, data, headers) on WebBrowser to let it post data
Both 2 methods failed to execute javascript after the result had been returned including script inside < script > tag in html and script I injected on LoadCompleted event. The javascript code is simple enough, I tested it thoroughly and made it works with WP8.1 version so it should be no error in my script (by the way, there is no good way to debug js in WP8 like WP8.1 even in Visual Studio 2013 - that sucks).
Anyone has any clue what is going with this old WebBrowser control or any workaround that I can go for this case?

The WebBrowser.IsScriptEnabled Property defaults to false. Set it to true if you know that the script in your page is safe and want to run it.

Related

Show local pdf inside webapplication [w/o remote server]

I'm developing a HTML5/.net POC in which I have a local HTML5 webapp shown inside a .net (C#) WebBrowser control.
The page is developed in asp.net MVC, downloaded as a single .htm file (using Chrome's SingleFile extension) and saved in a DB (or stored in a filesystem, doesn't matter), loaded and shown inside a .net webbrowser control.
[almost] Everything works: the page is rendered correctly, i can invoke js functions from C#, etc.
But now I have to show some pdf inline inside the page. The pdf is not served from a remote server (there's no server at all), but will be loaded from the filesystem (e.g. a temp file). The idea I have is to make a js function like showPdf(path, pageNum) in the html5 app and call it from .net.
The problem is that it looks there's no way (at least I couldn't find it) to load local pdf, both using Mozilla's pdf.js or html tags, I get "Not allowed to load local resource" in Chrome console/"Access denied" alert in IE.
Is there some kind of component I can try/option I can set to allow the browser to load local pdfs?
The WebBrowser component uses IE to render the page, so maybe some kind of IE option/key registry I can change (the machines that will eventually use this webapp are known, we can configure them as we want)?.
You could try a traditional anchor element (<a href="file:...">) and then enable the File Protocol Navigation feature control for your app. (And, though it may seem obvious, it's probably worth confirming that IE feature controls do not to enable functionality in other browsers.)
I don't know that this would work, but it seems like a possible solution given the question.
Note that accessing file objects may permission to access local file system objects may be disabled by other policies or security measures. More info/research may be needed.
Hope this helps...
-- Lance
I forgot to write here how I solved it:
well, it was a webapp shown inside a WinForm WebBrowser control, so I used this article to call a C# method from JS. The C# method used the default OS pdf reader to show the pdf inside the form.

Visual Studio project type for client-side javascript

Could somebody advise me on which project type should I use to develop client side of web-based app (HTML + JavaScript) for Visual Studio 2013?
I tried to create New, Web Site, ASP.NET Empty Web site, then manually added all .js files to the project, but this is not exactly what I need, because I am working on a client-side code only, and the Web server is not IIS.
Of course, when a script error occurs, I can select “Debug using selected debugger”, manually choose my project and jump into debugging. However, this is only a half-solution.
First, I cannot start debugger with F5 – it launches web page connected to local IIS instead.
Second, I have duplicate source trees in solution explorer- the debugger does not match my source files with files loaded with web pages.
I have also tried New, Other project types, Visual Studio solution, Add existing Web site, and played with Start Options, but without much success too. It launches page in IE, but with script debugging disabled (???), and it does not start the debugger anyway.
Is there an appropriate project type to write and debug JavaScript for IE?
PS: When installing VS, I selected C++ development, as my primary settings, which might hide some useful Web development features. And I would prefer not to change this.
UPDATE: Problem #1 (starting with F5) was solved by setting IE as default Web browser (I have used Firefox). After specifying “Specific page” in Start options F5 starts the page under debugger.
Is it possible to debug scripts under IE, leaving my favorite browser as default? If I specify “Start External program” and set “iexplore.exe” with page url, it launches the page but does not allow me to debug it.
you have a bunch of questions in here, but let me try answer them.
To develop client-side of web-based app, Create an ASP.NET Empty Web site and manually add HTML + JavaScript
If the Web Server is not IIS, then you can change, right-click on your project in VS-2013, and in properties,check Web properties.
To Debug your HTML and JavaScript in IE, then follow this:
you have to enable Script debugging in IE as follow:
let, if you have a function named FirstFunction() in your HTML page then
<script type="script/javascript">
function FirstFunction()
{
debugger;
alert("Debugging now");
}
</script>

Create ActiveXObject on *server*

I have created a little html stub that allows a user to compare various spellers. I would like to include the Word speller and I have written code in a .js file to create an ActiveXObject thus:
var wordApp = new ActiveXobject("Word.Application");
This works fine on my local machine but I get the dreaded 'Automation server can't create object' error when I try it on other machines. I have searched and read the various articles on the topic and I understand that what I am trying to do is very,very bad, not safe, doesn't work on any browser than IE, and so on. This is for an internal test app in a trusted environment and all I want is for others to be able to access the page and see the result without forcing them to make extreme changes to their security settings.
So, here is my question. Is there a way that I can get this to run server side on my machine running IIS and hosting the website? Ideally I would like to be able to insert my HTML into an aspx file and, when the submit button is pushed, have it either run all the javascript on server side or at least run the portion that calls the activeX code. If this isn't feasible, can I migrate the specific functions that call the activeX and get the data to C# or VB and still run the safer functions in JS?
Thanks for your advice!

How to execute shell scripts from a web page via javascript/jquery and get its results in a string?

in a simple html file opened locally via firefox I need some javascript code to execute a command (maybe "ls") and get it's result in a string I can use in js/jquery to alter the page contents.
I already know this is a generally bad idea, but I have to make this little local html file capable of running several scripts without a server and without cgi.
In the past I've used to install a plugin in TiddlyWiki (www.tiddlywiki.com) to execute external commands (firefox requested authorization for every operation), so javascript can do it, but how to get command result in js after execution?
I don't believe there's any way to do this without a cooperating browser plug-in. The browser plug-in would be told what command to execute via javascript, it would go execute that command and then call you back with a callback when the results were available. This could be very dangerous as giving the browser access to your local system in almost anyway opens you up to lots of types of attacks (which is why browsers don't offer this capability).

ActiveX control in IE intranet zone - blocked without a prompt?

I'm writing an intranet page for my company that requires the use of an embedded dll (COM). The dll is registered on all clients computers so it doesn't need to be downloaded from the page, it just needs to run.
I've tried using the following code to embed the control:
var newObj = new ActiveXObject("servername.classname");
And this works when testing locally, but from the intranet the object fails to instantiate with the js error "automation server can't create object". I suspect this is because IE(7) blocks ActiveX controls by default in the intranet zone. I've also tried using the <object> tag with no luck.
I have a deadline to get this finished and it's unlikely that the IT dept will get around to changing the company security settings before then, so unless its very straightforward for them to do it's not really an option.
So my question is: Is there any possible workaround that will allow me to embed the control so that it will at least prompt the user instead of silently blocking the control, without changing the default security settings in IE?
Almost everyone in the company uses some version of IE (up to 7), so it only needs to work for this.
All help and comments appreciated.
Thanks.
Update:
If this absolutely isn't possible, I'm looking at using the dll from a script on the server in this question. I'd still rather do it client side though because the control has some nice user interfaces available.
if you embed it with an <object> tag it should prompt you regardless; you could then make calls on it through the object tag. another trick which may work is to put: <!-- saved from url=(0013)about:internet --> as the first line of your html file; I don't know if this will work on the intranet zone, but from localhost that will cause the page to be treated as though it were an internet page.
I have used FireBreath plugins (which act as activex controls and can be called in the way you describe) and have never had an issue like this. Good luck!

Categories

Resources