Windows phone app, WebBrowser, iframe and google maps not working together - c#

I am having a problem with iframe and WebBrowser. In my app I have a page with WebBrowser which goes to specific url and should show a google map (embedded with iframe). However, it does not. Getting the error "This content cannot be displayed in a frame. To help protect the security of information you enter into this website, the publisher of this content does not allow it to be displayed in a frame."
But if I go to this url with the emulators browser everything works fine, same with ie in my pc. I also tested with other urls which dont have iframes and the WebBrowser works fine. I have also tried webBrowser.NavigateToString with the same code the url has but doesnt work either. I do have the &output=embed at the end of the map url in iframe. Also tried using my api key in the html.
What should I try next?

Im gonna answer to myself.
Adding this line in c#
webBrowser1.IsScriptEnabled = true;
and this in xaml
IsScriptEnabled="True"
did the trick.
So scripting is disabled in WebBrowser control by default.
Well, now I know.
Found the answer from here: http://www.jeffblankenburg.com/2010/10/18/31-days-of-windows-phone-day-18-webbrowser-control/

Related

HttpContext.Response.RedirectLocation doenst work in chrome

I have a multilanguage site. Available languages are English and Dutch. I would like to be able to switch between those languages. So when a visitor clicks on the NL language it will point to www.website.com/languagecontroller/switchlanguage/language=nl?currenturl=http%3a%2f%2fwww.website.com%2f (currenturl parameter will be url encoded).
The redirect to the page and correct language will be done via the code below:
HttpContext.Response.Clear();
HttpContext.Response.StatusCode = 302;
HttpContext.Response.RedirectLocation = currentUrl;
HttpContext.Response.End();
The result (only in Chrome) I get is a blank page with in the address bar: www.website.com/languagecontroller/switchlanguage/language=nl?currenturl=www.website.com
The coding seems fine because Internet Explorer and Firefox are working fine, only Chrome is having issues. I've also tried Server.Transfer() but I experienced the same issue there.
I've been searching for the issue and it looks like it has to do with Chrome caching. But I'm not sure and was not able to find the/a solution. I don't see what might be wrong or how I can fix this so Chrome doesn't give me issues.
Does anyone have an idea?
Please refer http://en.wikipedia.org/wiki/HTTP_location
RFC 2616 requires an absolute URL in the HTTP LOCATION header, your URL is not well formed (from what I see above), add (http://) and convert it to well-formed absolute URL. Check, perhaps that would solve the problem.
The issue seems to be in the URL.
Hope this helps.
thanks

Execute function from a webpage that is activated onclick

I have to make a console application in C# which retrieve some data from webpages.
I have downloaded the HTML code from the main page of a website.
WebClient client = new WebClient();
String htmlCode= client.DownloadString(linkToWebpage);
I have verified the string and it is good.
After this part, I have searched for a specific line in the html code which contains a button and a link.
<a rel="nofollow" class="link" onclick="loadornot()" href="http://aaaaa.com/D?WUrtlC1" target="_blank">Click to read more</a>
Now i am trying to download html code from the ancored link (the one from the href), but I am redirected to the main page and I am not sure why. Even if I copy the link from href and paste it into a webbrowser, I am redirected to the main page.
I believe that this happens because the button call a function onclick="loadornot()". That's why it doesn't work the way I have tried? And if yes, how could I call that function from my c# application to continue my app?
Thank you.
Edit:
I have found out that I need some cookies, more exactly, sessioncode, to make that link work. How can I do that?
You can't run javascript code from web page without browser. So, if you really need to execute that function in downloaded page, use some kind of headless browser, like those: webkitdotnet or awesomium

Getting the browser to show IFrame or use HttpOnly cookie on different page

Hello I'm developing a Windows Phone app for a web based game.
I have however run into a problem that I cant figure out how to solve, and hope some of you bright people in here have an idea.
I use a java script to log into the page no problem, but unfortunately the webpage is very badly designed and show up wrong on Windows Phone. The page will not scale and therefor only show a small part of the hole page and it is only possible to scroll up and down and not side ways.
I have made a quick image here to show better.
Link to image on ImageShack
(I dont have rep to post Images yet :-( )
So the actual game is inside an IFrame in the middle of the page but I can only see a small part of it on the phone and can not scroll horizontally.
I tried to download the page using string html = webBrowser1.SaveToString(); and then used a regex function to extract the webpage from the IFrame. The problem with this is that the page uses a HttpOnly Cookie and this cookie is used by the IFrame also to identify the user. So if I navigate directly to the IFrame Url, it wont recognize the user even though it has the cookie because it is on a different website..
So my question is is there a way to force the web-browser to focus on the IFrame, or some way of stripping out the rest of the page and only show IFrame but still use the same HttpOnly Cookie?
Can you make a wraps that iframe, then use the hastag trick ("http://game.com#divwrapper") to navigate to that div. This will scroll the page down

Facebook login page is mirrored when in RTL

I've set my WP8 app to be RTL (right to left) and than used the Facebook c# SDK for WP8.
This is my relevant Facebook c# code:
session = await FacebookSessionClient.LoginAsync();
Now the problem is that the Facebook log in page is all mirrored and unlike the WP8 mirror the texts are also mirrored so they are sort of "backwards".
Is it a bug or can I fix it?
Got it :)
Before the line in the question I added this:
App.RootFrame.FlowDirection = System.Windows.FlowDirection.LeftToRight;
To return the app into LTR so the Facebook page will be formatted correctly and not mirrored.
In order to return it after the login had finished I added this line when I finished with the login:
App.RootFrame.FlowDirection = System.Windows.FlowDirection.RightToLeft;
It happend because the facebook login page is shown inside a Browser control so the actual text doesn't get mirrored correctly.
I guess the Facebook C# SDK people should have thought of it.. so I think we can say it sort of a bug.
Hope I helped you, future viewers!

How to launch a browser and later direct it to a page?

I need to launch a browser, do some work and then make the browser navigate to a URL (in that order).
The first part is of course simple and I have a Process object. I am at a loss as to how to later direct it to the target page?
How do I treat the Process as a browser and make it navigate to the desired page?
Any help, pointers, code snippets appreciated.
Instead of launching the browser & then navigating to the page, just tell the OS that you want to run the URL. Windows will pick the correct browser, and navigate the user to the given URL.
System.Diagnostics.Process.Start("http://www.StackOverflow.com");
If you don't need to do this in production, you could use a testing library such as WatiN to do this:
using WatiN.Core;
//Placeholder page to launch initial browser
IE ie = new IE("http://www.google.com");
DoSomeWork();
//Now navigate to the page you want
ie.GoTo("http://stackoverflow.com");
My first instinct for this question was DDE, but it appears that has been decommissioned in Windows Vista so that is no good. Shame, as it was the only consistent mechanism in Windows for Interprocess Communication (IPC)...oh how I miss Arexx on the Amiga.
Anyhow, I believe the following will work but unfortunately, due to the way it works, it launches Internet Explorer irrespective of the configured browser.
If your application has a Form, then create a WebBrowser control on it. Set this to non-visible as we are only making use of its as a launching device rather than to display the web page.
In code, at the point where you want to show a web page, use the following code:
webBrowser1.DocumentText = "window.open('How to launch a browser and later direct it to a page?', 'BananasAreOhSoYummy');";
What this does is to tell the WebBrowser control, which is just the IE in disguise, to open a new window called 'BananasAreOhSoYummy'. Because we have given the window a name, we can use that line repeatedly, with different URLs, to change the page in that particular browser window. (A new window will be opened if the user has happened to close it.)
I will have a think about an approach that honours the user's default browser choice.
If you don't need the actual instance of IE, you can use the System.Windows.Forms.WebBrowser control.
I think instead of sending the browser a url you could send it javascript that would run and direct the browser to a site.
Not sure if this would work but I see no reason why it wouldn't

Categories

Resources