Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Webbrowser - disable page links

Status
Not open for further replies.

Kenny62

Programmer
Mar 3, 2004
54
GB
Hello - is there a simple way to configure the web-browser control such that all links on a displayed web page are disabled. (Only the URL set in the .Navigate method is displayed - users can't go to other sites).

Thanks for any help in advance, Ken.
 
not sure i understand exactly what you mean, and they me be only me. Are you saying that you want a paged displayed in the web browser, but any links that may be in the site to be disabled so that they can only see that one page?

Is that what you mean?
 
That's what i understood too. A little weird...
If you own the site you could have restrictions, authentication and authorization, login etc..

This should be in asp(.net) forum anyway
 
Hi - ralptrent, tipgiver - yeah that it what i meant. The app provides the URL - once the page is displayed - i don't want the user to navigate to other pages - hence need to disabled links. The pages are on a big intranet and the web. I have no control over the pages. All i know is the URL.
Can this be done at the browser control level or does it have done via the document object thro code. If so - how?
Yeah - it a little weird - but that its what management want.

Thanks, Ken.
 
You could use javascript to disable clicking right and left with the mouse. So you'll be able to watch only.

Do you like this?
 
But the user must have javascript of the browser enabled :(
So you have to force him enabled it first... and add some code to the page. This way sucks! Although i mentioned javascript i do not recommend it.

1. Think of providing the users with a simple app with a browser on it that will display the url (not known to users). This is a little better and safer than javascript.

2. There must exist a better idea, so wait for other posts too.
 
There is a way to download a the web page to the local machine using the System.Net class. I do not have the code here, I have it on another machine that I do not have access to right now. I will look at it and post the results.
 
I don't know Java - so that method is a no. no...surely there must be a easier method!
 
How about setting a boolean value to true when the .Navigate method is called then false again afterward. Then in the BeforeNavigate2 event set cancel = true if the boolean value is false and also set cancel = true in the NewWindow2.


Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'.
 
I think a simpler solution would be to disable left and right mouse button click on the browser client region - scrollbars need to work as normal. Any ideas how to do this.
 
You need code, pergaps javascript. This code must be in the head and ody of the page. As you won;t have access to modify the page, you should build a browser that mouse clicks are disabled.
 
it looks like the even _TitleChange for the web browser control might help you out. Create the event handler and when it is fired off, just have it go back to the page you want it to go to. The only problem is, the first time you run the app the TitleChange event will fire. You will need some sort of statement to stop that from happeneing the first time the app is kicked off.

Example:
Lets say that the site you want them to only visit it you can do this
Code:
private void wbWebBroswer_TitleChange(object sender, AxSHDocVw.DWebBrowserEvents2_TitleChangeEvent e)
{
wbWebBroswer.Navigate("[URL unfurl="true"]http://www.tek-tips.com");[/URL]
}
every time the title of the web page is different, it will force them back to tek-tips.com. If I figure out the code ill post it, but work with this event.
 
This is what I came up with :

Code:
private void wbWebBroswer_TitleChange(object sender, AxSHDocVw.DWebBrowserEvents2_TitleChangeEvent e)
{
	if (e.text.ToLower() != "google")
	{
            wbWebBroswer.Navigate("[URL unfurl="true"]http://www.google.com");[/URL]
	}
			
}
 
ralphtrent, your code looks remarkably like CSharp (or at least C-something)

I use the following to control whether or not to allow a page to be navigated to.

Simply change AllowPage to true and navigation is allowed and to false and it is prevented

Code:
  Private AllowPage As Boolean

  Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

    AllowPage = True
    wb.Navigate2("[URL unfurl="true"]www.google.com")[/URL]
    AllowPage = False

  End Sub

  Private Sub wb_BeforeNavigate2(ByVal sender As Object, ByVal e As AxSHDocVw.DWebBrowserEvents2_BeforeNavigate2Event) Handles wb.BeforeNavigate2

    e.cancel = Not AllowPage

  End Sub

Hope this helps.

[vampire][bat]
 
That is exactly what I was talking about but do not forget to also set e.cancel = true in the NewWindow2 event. This will prevent links from opening a page in a new window.


Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'.
 
Thanks for your help guys - especially 'earthandfire' - this is the kind of solution i've been looking for. Cheers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top