.net Open link from WebBrowser Control in a new Tab in IE - html

I have a web browser control in my application which contains the following link:
<html>
<body>
test
</body>
</html>
Each time I click on this link, it gets opened in a new window of IE instead of a new Tab. I tried loading this html directly in IE - then it correctly gets opened in new tabs.
I have also configured the IE setting to open links in new tabs instead of new windows.
Can anyone help me out to load the links from the web browser control in a new tab?
Thank you!

It would have been helpful if you had specified whether you were using Winforms or WPF for your web browser control or even what language you were using (C#, VB,F#, etc) but assuming you are using winforms and C# this solution would work.
You simply cancel the new window event and handle the navigation and tab stuff yourself.
Here is a fully working example.
using System.ComponentModel;
using System.Windows.Forms;
namespace stackoverflow2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.webBrowser1.NewWindow += WebBrowser1_NewWindow;
this.webBrowser1.Navigated += Wb_Navigated;
this.webBrowser1.DocumentText=
"<html>"+
"<head><title>Title</title></head>"+
"<body>"+
"<a href = 'http://www.google.com' target = 'abc' > test </a>"+
"</body>"+
"</html>";
}
private void WebBrowser1_NewWindow(object sender, CancelEventArgs e)
{
e.Cancel = true; //stop normal new window activity
//get the url you were trying to navigate to
var url= webBrowser1.Document.ActiveElement.GetAttribute("href");
//set up the tabs
TabPage tp = new TabPage();
var wb = new WebBrowser();
wb.Navigated += Wb_Navigated;
wb.Size = this.webBrowser1.Size;
tp.Controls.Add(wb);
wb.Navigate(url);
this.tabControl1.Controls.Add(tp);
tabControl1.SelectedTab = tp;
}
private void Wb_Navigated(object sender, WebBrowserNavigatedEventArgs e)
{
tabControl1.SelectedTab.Text = (sender as WebBrowser).DocumentTitle;
}
}
}

Related

Xamarin.Forms WindowsPhone Landscape NavigationPage shows black area

I have a strange behaviour in my Xamarin.Forms app on the WinPhone client.
My MainPage is a NavigationPage. And when I navigate to the second page and turn the phone to landscape (also happens on the other way), the page shows a black area on the right side. It seems that the height and width properties don't get re-calculated on the device orientation change.
To reproduce this, just create a new Xamarin.Forms Blank App (Visual Studio 2013 template), Update the Xamarin.Forms nuget to the newest verson (in my case: 2.0.0.6490), and add the following to the App-Constructor:
var second = new ContentPage
{
BackgroundColor = Color.Green,
Content = new StackLayout
{
VerticalOptions = LayoutOptions.Center,
Children = {
new Label {
XAlign = TextAlignment.Center,
Text = "Second Page"
}
}
}
};
var button = new Button {Text = "Show Second"};
button.Clicked += async (sender, args) => { await ((NavigationPage) MainPage).PushAsync(second); };
var firstpage = new ContentPage
{
BackgroundColor = Color.Blue,
Content = new StackLayout
{
VerticalOptions = LayoutOptions.Center,
Children = {
new Label {
XAlign = TextAlignment.Center,
Text = "First Page"
},
button
}
}
};
// The root page of your application
MainPage = new NavigationPage(firstpage);
Is this a bug in Xamarin.Forms? Or miss I just something? Thanks in advance
I cant see any existing filed bugs on this. If it is easily reproducible as described, then create a small repro project and submit to bugzilla.xamarin.com. It will be a xf regression bug.
Thanks #Joehl - I obviously am not too great at searching bugzilla on my mobile. As mentioned this is the bug report: https://bugzilla.xamarin.com/show_bug.cgi?id=36477

Disable Chrome paste menu on text inputs while on a touch screen

How to disable this annoying contextmenu in chrome while on a touch screen. This pops up on selection/on long tap of any input while i have some text copied.
Am developing an app using CEFSharp (Chromium Embedded Framework) and its going to be deployed on touch screen on windows 8 machine. am using a on screen keyboard(http://mottie.github.io/Keyboard/) for entering text in input fields.
I have tried
$('input').bind('copy paste contextmenu', function (e) {
e.preventDefault();
e.stopPropagation();
});
this disables the pasting but the menu still shows up. how do i get rid of this menu? how best to approch this: CSS , Javascript or through chrome command line arguments (http://peter.sh/experiments/chromium-command-line-switches/) ?
i know you said JS / CSS, but this worked for me
var browser = new ChromiumWebBrowser("http://www.afrobotics.co.za")
{
Dock = DockStyle.Fill,
DragHandler = new DragHandler(),
MenuHandler = new ContextHandler()
};
//
public class ContextHandler : IMenuHandler
{
public bool OnBeforeContextMenu(IWebBrowser browser, IContextMenuParams parameters)
{
return false;
}
}
public class DragHandler : IDragHandler
{
public bool OnDragEnter(IWebBrowser browser, IDragData dragData, DragOperationsMask mask)
{
return true;
}
}

Open external .swf in another frame or window

I am trying to link to an external .swf file, which I have done, but it opens as a popup within the main .swf. What I want to do is either have it navigate to a blank frame with the external .swf there or have it open in a new window. How do I achieve this?
Here is the code I have which opens the external .swf:
private function openSWF():void {
cSWFLoader = new Loader();
cSWFPopup = addChild(cSWFLoader);
cSWFLoader.x = cPopX;
cSWFLoader.y = cPopY;
try {
cSWFLoader.load(new URLRequest(cSourceFile));
cSWFLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, SWFLoaded);
}catch (err:Error){
trace("YOU DONE GOOFED", cSourceFile);
trace("Error: ", err);
cSourceFile = null;
}
}
private function SWFLoaded(evt:Event):void{
cSWFLoader.addEventListener(MouseEvent.MOUSE_DOWN, dragSWF);
cSWFLoader.addEventListener(MouseEvent.MOUSE_UP, dropSWF);
cSWFPopup.content.gotoAndStop(cFrameLabel);
cSWFPopup.content.closeBtn.addEventListener(MouseEvent.CLICK, closeSWF);
cSWFLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, SWFLoaded);
}
Thanks in advance

DocumentComplete event is not fired when loading local HTML page

I'm loading a local HTML file into IE and expecting to receive a DocumentComplete event. It's never fired. I also tried NavigateComplete and ProgressChange but they aren't fired as well. Here is the code:
public void OnDocumentCompleted(object pdisp, ref object url)
{
Console.WriteLine("DocumentCompleted fired on url {0}!", url);
}
var IE = new InternetExplorer();
object Empty = 0;
IE.NavigateComplete2 += new DWebBrowserEvents2_NavigateComplete2EventHandler(e.OnNavigateComplete2);
IE.DocumentComplete += new DWebBrowserEvents2_DocumentCompleteEventHandler(e.OnDocumentCompleted);
IE.ProgressChange += new DWebBrowserEvents2_ProgressChangeEventHandler(e.OnProgressChange);
var uri = new Uri("file://c:/iframeExample.html");
IE.Navigate(uri.AbsolutePath);
IE.Quit();
If I'm browsing to a page on the web, I do receive all events. So, why they are not fired for a local page?

How to add tooltip in map windows phone 8?

My windows 8 phone app programatically add an image (as a pin) to a specific coordinataion in map using mapoverlay. And now i would like to add a tooltip to the image (pin) after tapping on it. Does anyone know how to fix this?
pinIMG = new Image();
pinIMG.Source = new System.Windows.Media.Imaging.BitmapImage(new Uri("/Assets/pin.png", UriKind.Relative));
MapOverlay myLocationOverlay = new MapOverlay();
myLocationOverlay.Content = pinIMG;
myLocationOverlay.PositionOrigin = new Point(0.5, 0.5);
myLocationOverlay.GeoCoordinate = new GeoCoordinate(57.724611, 12.938945);
MapLayer myLocationLayer = new MapLayer();
myLocationLayer.Add(myLocationOverlay);
MyMap.Layers.Add(myLocationLayer);
Instead of adding an Image to the MapOverlay, consider adding an ExpanderView control that expands to add additional data. You'll need to download the Windows Phone Toolkit to get the ExpanderView control. While you're at it you might want to switch over to using Map Extensions Pushpins to get databinding support.
private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
MapLayer myLayer = new MapLayer();
MapOverlay myOverlay = new MapOverlay()
{
GeoCoordinate = new GeoCoordinate(-17, 133)
};
ExpanderView expander = new ExpanderView();
expander.Header = new Image()
{
Source = new BitmapImage(new Uri("Assets/ApplicationIcon.png", UriKind.Relative)),
Width = 200
};
expander.ItemsSource = new[]
{
new TextBlock{ Text = "HELLO"}
};
;
myOverlay.Content = expander;
myLayer.Add(myOverlay);
myMap.Layers.Add(myLayer);
}
When we run this sample we can see the following icon over australia:
And once we click ti we can see our "Hello" text show up:
A few ceavets: the code sample above is terrible. ExpanderView is meant to use both ItemSource and IteTemplate for multiple items databinding. Using it for a single item isn't great. The above code sample is also terrible since it creates UI elements in C# code whereas using Map Extensions could have placed this code in XAML.