ShowURL and Popup blocker

Hello,

I try to open a new external page on another tab. Therefore I use ShowURL. But if the popup blocker is active, the new Page don’t open. I saw in the help that there is an event which tells that the popup blocker is active. But I can’t find the event in Studio.

The LR is your friend :
http://documentation.xojo.com/index.php/WebPage.PopupBlocked which is triggered when WebPage.Show is done for a new window.

But with ShowURL, it fails silently:
http://documentation.xojo.com/index.php/WebControl.ShowURL

You better use a link with the option to open in a new window. Since the link will be activated by the user, the new window will not be blocked.

Thank you for the reply. I found both entries in the documentation. My problem is that I wants to call an external URL. As I understood this is only with the ShowURL method possible. On the other hand this method don’t throws the event for PopupBlocked.

The original problem was, that I wants to call an external URL in a new window. But with the flag True in the ShowURL method it works only without popup blocker. So I need a method to find out that the popup blocker is active. If it is active, I can show a message.

All the method seem to simply try to open a new window and manage the error.
https://duckduckgo.com/?q=javascript+detect+popup+blocker&ia=qa

You can apply one of them in JavaScript, but that may be more complex than doing a WebPage.show and manage the PopupBlocked event. At any rate, what you can do is :

  • In the shown event of the webpage you show in the new window, do a ShowURL to your other site
  • If the popup is blocked, present the user with a link to click in order to open the new window, link in question pointing to your other site page.

Given the fact that most every browser today come with popup blocked by default, I am inclined to suggest you spare yourself the process, and directly instruct the user to click on a link. That way they will always see the new page.

Hello,

thanks for the help. The second way seems to be the right one. But I’m not possible to give the show method a parameter to open the webpage in a new window. Nor I’m able to get event. Do you know if there is an example. Or, from which Control do you start the show?

Thanks for an answer

WebPage.Show has a parameter http://documentation.xojo.com/index.php/WebPage.Show

Links have the option to open a new window. And since they are user initiated, they are never blocked :
http://documentation.xojo.com/index.php/WebControl.ShowURL

Hello,

yes, this I was reading, too. But when I try to enter it like “AufrufSeite.Show( true)” I get an error message “Too many arguments: got 1, expected 0”. “Aufrufseite” is the Webpage I wants to open.

Michael, your idea sounds great but seems no longer possible: [quote]“Beginning with 2011r2, Show does not take the optional parameter InNewWindow.”[/quote] and the PopupBlocked does no longer exists either…

this is the reason. I use the actual version. But it helps me not ;-(

I told in the first place to use Link, because I know it always work.

hello, the problem is, that I can’t at this place no link. I need some more graphics. But thank you for the tips.

Hello,

this didn’t worked well, But with it I got an idea - and it works now. Here I wants to show you the solution.

I created a method, which open an external Link ands checks for the popup-blocker

	Dim JavaScriptCode As String
	
	JavaScriptCode = ErsetzeText( StarteLinkJS, EinURL, ResFehlerPopupBlocker)
	EinSeite.ExecuteJavaScript( JavaScriptCode)

This method gets to parameter. First the Webpage (EinSeite) to get the method (ExecuteJavaScript) within it. The second one is the URL.

The javascript (JavaScriptCode) is defined as a constant

var popup = window.open("^1");
try {
popup.focus();
} catch (e) {
alert(’^2’);
}

ErsetzeText is a method I defined earlier. It replaces ^1 and ^2 with the first and second parameter.

The javascript tries to open the link and in the case of an error it displays the message. With the message, the user is informed that he must deactivate the popup-blocker to open the link.

For me this works great. I hope I can help other users, too

Talk about wasting time :confused:

sorry, I copied it into my Xojo project and tried to start it. Then I got the error message

Could not execute returned javascript: Argument 1 (‘node’) to Node.appendChild must be an instance of Node
Source: var ctrl = document.getElementById(‘TBZ2ivmg’);var link = document.createElement(‘a’); link.setAttribute(‘href’, ‘https://CheckWriter-Printer.com’);link.setAttribute(‘target’, ‘_blank’);ctrl.appendChild(link); link.appendChild(ctrl.getElementsByTagName(‘canvas’)[0]);

Because I’m not an javascript expert I didn’t found the error. On the other hand I read about above example. So I took at basis for my solution.

But your work was not useless. It was one basis.