HTMLviewer not opening targeted URLs

I have an HTML viewer opening a website of mine. The issue is I have a lot of URLs that have target="_new" or target="_blank" then these are clicked on inside the web viewer nothing happens. I know they are not truly blocked, just the HTML viewer fails to handle them.

I looked thru many threads on here and really haven’t seen this specific problem mentioned or it was o old I didn’t get to it.

I have seen mention of cancel load to handle these things, but I don’t really see a way of grabbing the link URL that was clicked. I am hoping to do this inside of Xojo and not having to pay $300 for a set of plugins if at all possible.

Or can the web page be rewritten before it’s given to the HTML viewer, that way if I can find links that have target="_new" and change it somehow?

I can not believe such a small thing has turned into this big of a headache; there are millions of web pages that use target URLs and need a way to open them.

http://documentation.xojo.com/index.php/HTMLViewer.NewWindow

And for an example project that shows it in action:

Examples/Desktop/ContainerControls/TabbedWebBrowser

Thanks guys I’ll take a look at the examples

Ok looking at the example it seems to create a new tab for the url to open in, did not see a way to capture the url it’s trying to open so I can use showurl instead inside of the NewWindow event. Am I missing something?

The NewWindow event you return a HTMLViewer to send the requested url to. You don’t know what that URL is, you just tell it where to show up.

Thanks everyone for the help so far, but I want to tell it to show up in the Systems web browser not in a new htmlviewer, it has to be defined somewhere… I am just trying to access the URL it would open a new htmlviewer to and use showurl instead.

I want to send URLs that target new windows into a real web browser outside the Xojo app

http://documentation.xojo.com/index.php/HTMLViewer.CancelLoad
http://documentation.xojo.com/index.php/HTMLViewer.NewWindow
http://documentation.xojo.com/index.php/ShowURL

Michel thanks, I been through a dozen threads on the cancel load, the examples didn’t seem to work correctly and they were copied verbatim. It seems cancel load wants to repeat itself over a dozen times on the webpage due to so many links on it.

So using some of the examples I had like 30 browsers opening up. Trust me, I tried for hours before starting this thread. I can not believe there isn’t a variable somewhere for the new URL the html.newwinodw is trying to open.

OK. Here is the solution. I am going to explain how it works instead of simply posting a recipe.

NewWindow gives you a new HTMLViewer instance to display the _Windows URL in. If you return it, the URL will display in the HTMLViewer. If you do not return NewWindow, the link is simply ignored.

So the trick is to differentiate between regular and popup.

  • Add a NewWin boolean property to your window

In NewWindow, set NewWin True, and return the HTMLViewer (Not NewWindow) :

Function NewWindow() As HTMLViewer NewWin = True Return me End Function

At this point, the next URL to load will be the popup one. So in CancelLoad, check if NewWin is true, and if so, ShowURL :

Function CancelLoad(URL as String) As Boolean If NewWin then ShowURL(URL) NewWin = False Return True end if End Function

Michel you are the man, that worked great

where i should write that code?

i solve like this:

If NewWin then
window2.HTMLViewer2.LoadURL(URL)
window2.Visible = True
NewWin = False
Return True
end if

thanks all of u!!!

I guess, handling asp popups? any way to force them to load in the htmlviewer? when you click nothing happens.

http://www.public-access.riverside.courts.ca.gov/OpenAccess/

Click Civil (Left)

Search by Case Number

COC 1906157

You will see a result come up, when you click on the Case number the link does nothing.

but in a normal browser. this link is opened.

http://public-access.riverside.courts.ca.gov/OpenAccess/Civil/CivilCaseReport.asp?CourtCode=A&RivInd=RIV&CaseType=COC&CaseNumber=1906157

while I can create a string every time I want to open a case. Not every region is the same, so this will force me to create specific variables for this county and court…

I’d like to just force the load into the same window…

The link is a JavaScript open window :

<!--<td><font color="#000000" face="arial"><small><A HREF="javascript:OpenCase('A','COC','1906157');">COC1906157</A>&nbsp;-->

It is difficult to interpret, since the OpenCase JS method is elsewhere.

[code]function OpenCase(CourtCode,CaseType,CaseNumber)
{
var URL = “CivilCaseReport.asp”;
URL += “?CourtCode=” + CourtCode;
URL += “&RivInd=” + document.getElementById(“hidRivInd”).value;
URL += “&CaseType=” + CaseType;
URL += “&CaseNumber=” + CaseNumber;

//START DEV6981 GSK 09/14/2010
var s = "spanrow" + CaseType + CaseNumber;
var spanrow = document.getElementById(s);
if (spanrow != null)
{
	s = spanrow.innerHTML;
	s = s.replace(/#0000FF/i, "#CC00CC");
	spanrow.innerHTML = s;
}
//END   DEV6981 GSK 09/14/2010

var w = self.screen.width -30;
var h = self.screen.height-150;
var options = "";
options += "left=10,top=10,screenX=10,screenY=10,";
options += "toolbar=yes,location=yes,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes";
var ViewCaseWindow = window.open(URL,"ViewCaseWindow",options);
ViewCaseWindow.focus();

}
[/code]

Unless you embark in analyzing the whole content of the DOM, I would tend to send all JavaScript to the default browser in this instance. You should have this in CancelLoad with some luck:

javascript:OpenCase('A','COC','1906157');

Then I guess you want to ExecuteJavascript the small part after the “javascript:” prefix.

I did not have time to test, but it should display the case.

Personally, I would stay away from trying to manage heavily JavaScript automated sites. HTMLViewer is not really made for that. Better send to the default browser.

@Michel Bujardet - interesting, so regardless - If i wanted to work it through JS - I’d have to separate the string to get the identifier “COC” and the case number in the right spot to call… So it would take just as much time create a variable for state and county and pass the constructed link without messing with javascript…

This would be kind of a hack, but I believe all is in the final URL:

http://public-access.riverside.courts.ca.gov/OpenAccess/Civil/CivilCaseReport.asp?CourtCode=A&RivInd=RIV&CaseType=COC&CaseNumber=1906157

Instead of trying to go through the JS UI, you could build the URL with the type and number you want, and display the page in HTMLViewer.