1 Attachment(s)
Openning New Window Using Web Browser Control
I have created a browser using the Web Browser control. Often when you click a link or a button on a web page, a new smaller browser window opens up. An idea example is the Manage Attachments button in this forum on the page where users type their questions.
What I find is though the new window opens up in my browser, the size of the Form remains as it is & the browser occupies just a part of the Form leaving the remaining part of the Form naked. Have a look at the attached browser image which opens up when the Manage Attachments button in this forum is clicked. Note the huge grey area on the right-hand side. Since the new browser window doesn't cover the entire Form, the grey area of the Form remains as it is.
How do I overcome this & ensure that when a smaller new browser window opens, the Form adjusts its dimensions according to the dimensions of the Web Browser control?
Re: Openning New Window Using Web Browser Control
How are you specifying the new link to go to? Dont use the webbrowsers Navigate2 or similar method. Use an anchor tag in the link to open on your page. And maybe evevn specify the "Target=_New" tag too.
Re: Openning New Window Using Web Browser Control
I believe you haven't understood the question. Why should I specify a link? I am not creating websites & web pages. The links & buttons for users to navigate from one page to another are already present in the websites. For e.g. Microsoft has developed Internet Explorer. Whether a link or button should open a new window or not, IE doesn't dictate it. It is the website developers who decide whether clicking a link or a button should open a new window or not. Let me try to clarify it.
I made a browser using the Web Browser control. I give the browser to you & you install it in your machine. You navigate to VBForums.com to ask a question & then go to the page wherein you type your question. You also need to attach an image along with your question; so you click the Manage Attachments button. A new browser window opens up which looks like the image I have attached in thread #1 of this post in which about 40% of the Form is uncovered since the Manage Attachments button has been programmed (by whoever has created VBForums.com) in such a way that clicking it opens a new smaller browser window. I want to get rid of that 40% of the uncovered Form. How do I do this?
I hope I have explained myself lucidly.
Re: Openning New Window Using Web Browser Control
The WebBrowser control has an event named ClientToHostWindow which expects 2 parameters - CX & CY. With the following code, to some extent I could make the new browser window open as it has been programmed to open (in a smaller window):
Code:
Private Sub wWeb_ClientToHostWindow(CX As Long, CY As Long)
Me.WindowState = vbNormal
Me.Width = CX * Screen.TwipsPerPixelX
Me.Height = CY * Screen.TwipsPerPixelY
End Sub
When I clicked the Manage Attachments button in this forum (on the page where one has to type his question), it opened a new smaller window with the correct dimensions (i.e. the width & height of the Form was the same as the width & height of the browser & hence no part of the underlying Form was visible) but I coded a simple HTML page with a button & the following code:
Code:
<html>
<head>
<script language="JavaScript">
function newWindow(){
newWin=open("NewWindow.html","popup","top=20,left=200,width=500,height=470,location=no,status=no,directories=no,scrollbars=no")
}
</script>
</head>
<body>
<input type=button value="OPEN NEW WINDOW" onClick="newWindow()">
</body>
</html>
so that a new window with smaller dimensions opens up when the OPEN NEW WINDOW button is clicked but when I clicked the button to open a new window, though the width & the height of the new browser opened as it has been set in the above JavaScript code, the width of the Form far exceeded the width of the browser & hence a large part of the underlying Form was still visible.
The reason why clicking the Manage Attachments button opened the new window with the correct dimensions but clicking the OPEN NEW WINDOW didn't could be due to the way in which the 2 buttons are coded to open the new window. Maybe the Manage Attachments button has not been coded using the JavaScript open method to open the new window which is how I have made the new browser to open though I couldn't detect it by having a look at the source code.
Any other suggestions, friend?
Re: Openning New Window Using Web Browser Control
Well you didnt explain all that in your first post so it seems you have it under control now. Btw, the manage attachments button does use some complex JavaScript to open the new window instance.
Re: Openning New Window Using Web Browser Control
Yes to a large extent, I think I have managed to resolve this issue but one problem still remains. When the Manage Attachments button is clicked, you will find that the new window that opens does not have the menubar, toolbar. address bar & also the status bar. How do I do this?
One way to do it is to read the code in the web page to find out if there's anything like location=no;status=no;directories=no (refer to the HTML code in post #4 of this thread) & if it exists, hide the toolbar, address bar & status bar (though menubar cannot be hidden) but the problem is this definitely isn't the only way to open a new browser window; there must be so many other ways to do it.
So how do I find out if the new window should be opened without the status bar, address bar etc & hide them accordingly?
Re: Openning New Window Using Web Browser Control
Well as you can see from the sites code that it has its own procedure for doing so - open_window. If you view the source of the calling page by right clicking and selecting "View Source" you will see what I mean.
Are you trying to automate VBF or ??? because this will be different for other sites.
Re: Openning New Window Using Web Browser Control
No....no....I am not trying to automate VBF. All I want is if any new windows are opened by clicking a link or a button in any web page, the new window should open as it has been programmed to open. In other words, if a new window is programmed to open with height=500 & width=400, I want that when my browser is being used, the new browser window's height should be 500 & its width should be 400. If the new window is programmed to open without the status bar, the new window shouldn't have the status bar when my browser is used.
The bottomline is I want the new browser window to adhere to the dimensions & specifications, if any, set by the website programmer.
Re: Openning New Window Using Web Browser Control
Then dont use VBF as your example as its a specific situation and its new windows are not handled the same way other sites do. Well maybe someone else can "spend" their time on this then.
Re: Openning New Window Using Web Browser Control
VBF is just one of the many sites which I have used to find whether new windows are opening with the specified dimensions & specifications (as coded by the web programmer). Yeah.....they are opening with the correct dimensions but not with the correct specifications. By specifications, I mean menubar, toolbar, statusbar etc...
1 Attachment(s)
Re: Openning New Window Using Web Browser Control
RobDog, though I have managed to open new windows with the dimensions specified, a trivial issue still exists. To change the dimensions of the new window, it's quite obvious that the WindowState property of the new window has to be set to vbNormal (since dimensions of a maximized window cannot be changed). I am doing this as well as altering the dimensions of the new window in the WebBrowser's ClientToHostWindow event.
Now have a look at the attached image. You will see 3 browser windows. Surprised? Here's the explanation - when a user clicks a button to open a new window (the button resides in the largest window at the back in the attached image), since I am changing the WindowState property of the new window from vbMaximized to vbNormal, as soon as the button is clicked, users can see that a new browser window has opened...that's fine...no problem with that but users can also see the new window changing its state from maximized to normal & that is what the middle window in the attached image is (the entire window is not visible but you can easily make out from the title bar & a good part of the menubar) though users finally see the new browser window (the window at the very front in the attached image). The middle window appears for less than a second but this effect can easily be seen taking place.
Is there any way by which I can avoid users seeing this effect (of changing the window state of the new window from maximized to normal) or even minimize this effect as far as possible?
I could manage to take a preview of this effect by pressing the Print Screen key on the keyboard just a fraction of a second after clicking the button (that opens the new browser window) in the largest window.