My application opens up a HTML page as a popup and it is getting opened in a different window. (Browser : IE8)
I need to read the HTML content of this popup and close it afterwards.
I have been looking at different alternative of using FindWindow functions etc but no luck yet.
Any help would be appreciated. Thanks.
I'm not sure how you're opening the popup, but this article should help: http://www.quirksmode.org/js/popup.html
Notice how you have to declare a new variable, newwindow, that holds a reference to the popup window. From there, it's a simple `$(window).html().
You might add this to the onclick() of a link.
var newwindow = window.open(url,'name','height=200,width=150');
if (window.focus) {
newwindow.focus();
}
var html = $(newwindow).html();
return false; // if it's a link, you have to prevent it from opening the link's
//address in the original window
Edit: if you're not the one opening the popup, things are more iffy. You can get a reference to the topmost window using window.top, but that's about all I know, especially because the situation isn't quite clear.
Related
I'm trying to set the cursor in an open document, but it doesn't show. I can see that the line is "marked" and I can "navigate" the lines, but the cursor is not shown, and thus I'm not able to write anything. Also it seems like the document doesn't really fully load, since guidelines and the navigationmap is not shown either.
Which makes me believe that the focus isn't being set completely inside the document.
I have confirmed that the focus indeed is not set in the document in the window, since If I have the output window focused before, it's still focused after the window.Activate() method has been called.
I've used the common way of opening the document through ProjectItem.Open(Constants.vsViewKindCode), activating it, and using the TextSelection.GotoLine(1,false) method.
This correctly shows the document and sets the line correctly, but I have to manually click inside the document for the cursor to appear.
The code I have:
Window window = projItem.Open(Constants.vsViewKindCode);
window.Activate(); <----- this does not focus the window.
TextSelection textSelection = window.Document.Selection as TextSelection;
textSelection.GotoLine(1, false);
I want to not have to manually click inside the document for it to load completely and for me to be able to write in it.
Hope someone can help me.
Oh well, another issue I had to solve by myself... Two for two. I guess people don't know that much in here like I'd hoped. Oh well.
Anywho, I discovered that if you use DTE.ItemOperations.OpenFile(path); and nothing else,
the file will receive focus correctly, just like it should have when you use .Activate().
So I have a link I'm trying to click on a WebBrowser control. The problem is it pops up in a new tab, making IE open. I can't manage the web pages after it opens in IE, so I need to force it to somehow stay within my program. It doesn't matter if another WebBrowser control needs to open or anything, just so long as it says in my program.
there are a few ways you can do this, one way is to loop through the DOM (Document Object Model) and find the link which opens in a new window, and change its "target=" attribute value to "target=_top" this way it will open in current top-level page of your current WB Control container.
Otherwise, there is a NewWindow2 event which you can intercept, write the following code inside that event (where WB1 is you WebBrowser Controls name):
Processed = True
WB1.Navigate2 URL
This will tell your WB Control that the request has been processed (tricking it into believing that it has been processed), and if you just did this, nothing would happen, so after the first line you write the second line which tells it to open the URL that it just tried to open in the new window, in the current window (WB1), so really you are just reissuing the request but for the same container/WB Control where the link was clicked.
I've written the code in VB, however I'm sure it's not a problem to understand and transfer to c#.
Let me know how you get along and if there is anything else i can do to help.
I'm aware that this title doesn't say much but it's really hart to explain what I want in few words.
I have two forms (main & help). Once I press button on main form help form pop ups. What I would like to implement is function to block user from doing anything on main form till he close help form.
I would not like to play with visible controls but I would like to have an effect you might have seen on some program that when user tries to click on main form help form "blinks" along with error sound playing. Once user close help form program works as usual
Hope you understand what I meant
This is called a modal dialog, and luckily, the answer is simple; show the child Form with the ShowDialog method instead of using Show. This is a blocking call that will not return until the child form/dialog is closed, so it means that you can check the return value and any properties if needed right after that line of code (probably not useful for a help window, but in most circumstances it is useful to check the user's action).
using( var dlg = new MyHelpDialog() )
{
if( dlg.ShowDialog() == DialogResult.OK )
{
// user chose "OK", do something (?)
// you can also access properties of the form after the fact
string whatever = dlg.SomeStringProperty;
}
}
You're looking for modal forms:
How to: Display Modal and Modeless Windows Forms
The thing you're talking about is called a "Modal Window".
See
How to: Display Modal and Modeless Windows Forms
I have seen umpteen posts talking about working with pop window using window handle.
But how to work with a browser which is opened when clicked on a button -
<button class="power_buy_now_button" type="button">
</button>
I tried to get window handle but each time I encounter a changing string, some thing like - "8c5f028e-e7cc-4d0f-afe4-983bb119391e"
There is not even title associated with new browser. More over I am not sure how I would use title to bring control to new browser. And then at some point I would have to bring control back to first browser.
Your best bet is to do something like the following:
// This code assumes you start with only one browser window in your test.
// If you have more than one browser window, your code will be more complex.
string originalHandle = driver.GetWindowHandle();
driver.FindElement(By.ClassName("power_buy_now_button")).Click();
// May need to wait for window handles collection to have a .Count of 2,
// as clicks are asynchronous.
string popupHandle = string.Empty;
ReadOnlyCollection<string> windowHandles = driver.GetWindowHandles();
foreach (string handle in windowHandles)
{
if (handle != originalHandle)
{
popupHandle = handle;
break;
}
}
driver.SwitchTo().Window(popupHandle);
// Do stuff in the popup window, eventually closing it with driver.Close()
driver.SwitchTo().Window(originalHandle);
I ended up in picking second handle and click on that. This approach works and I hope I would be able to get control back to main window also.
I have a web app that launches from an online portal into a new browser window. Everything works out fine until I try to open a new window or close the window from the webapp. Everything works fine when I test it locally though.
From what I've understood so far, after some Googling, it seems that this is because you can't call client side code from server side, for security reasons. I'll post what I've tried to implement for the Open and Close functions below:
Open
String javaScript = "window.open('http://www.google.com', null, 'height=555,width=760,
status=yes,toolbar=no,menubar=no,
location=no, scrollbars=yes');";
ScriptManager.RegisterStartupScript(this, typeof(string), "OPEN_WINDOW", javaScript, true);
Close
Close Window
as well as a simple
Close
in the HTML itself.
I know this question has been asked countless times before, but I've gone diving in the forums and Google and still can't find something that works, so I appreciate any help in this.
For now I'm suspecting that the problem lies in trying to call a pop-up window from another pop-up window for the Open function, while for the Close function, the server does not recognize the handle of the window that opened the pop-up.
Edit:
My apologies to everyone if I didn't make myself clear enough. I'll try to explain in more detail here.
Basically, in my web application, I have these 2 buttons, Open and Close.
The Open button will open up a link to another website in a brand new browser window.
The Close button will close the browser window that the application is residing in.
When I tested it out locally, i.e. localhost:xxxxx/Game.aspx, everything works fine. However, the app currently does not reside in a separate pop-up window called from another browser window
On the test server, the application is launched into a new browser window from an online game repository portal.
So just to re-illustrate the way I want it to work:
1. User logs into game repository page
2. User chooses a game to play
3. Game pops up in a new browser window
4. When user clicks on Open button, another new window pops up to a specific website(Does not work)
5. When user clicks on Close button, the game window closes itself(Does not work)
I hope this makes the issue clearer. Thanks.
I'm not totally getting what you are trying to say, but hopefully i understand enough. You need to call Close() on the window object that you opened. So change your javascript to this:
string js = "var myWindow = window.open('http://www.google.com', null, 'height=555,width=760,
status=yes,toolbar=no,menubar=no,
location=no, scrollbars=yes');";
ScriptManager.RegisterStartupScript(this, typeof(string), "OPEN_WINDOW", js, true);
and then in your page:
Close
If it helps then check this MSDN article.
Associate the popup windows to a variable which can in turn help you control the window which you will be closing, hence:
// Define the variable for the popup window
// You can use this to check if the window was indeed opened, before attempting to close
var myOpenedWindow = '';
// Open Window
myOpenedWindow = window.open('http://www.google.com', Null, 'height=555,width=760, status=yes,toolbar=no,menubar=no, location=no, scrollbars=yes');
// Close Window Function
function closeMyWindow() {
// Check for window instance being open
if (myOpenedWindow != '') {
// Close the window
myOpenedWindow.close();
// Clear the variable
myOpenedWindow = '';
}
}
// Close Window [DIRECT]
closeMyWindow();
/* OR */
// Close Window [FROM POPPED WINDOW]
window.opener.closeMyWindow();
There's plenty of ways to control your popped windows, and hopefully with these examples you can better understand how to control them.