Cancel navigation for FMX TWebBrowser - delphi

I'm using using a TWebBrowser in a FireMonkey app (Delphi 10.3.3) and loading some dynamic HTML into it like this
DocumentWebBrowser.LoadFromStrings(browser_html,'');
In that HTML I have several links like
<a id="position_26" class="cdimmed" href="pos_26">SOME WORD</a>
I need to intercept when the user follows that link, without loading new HTML (just by running some JavaScript). DocumentWebBrowserShouldStartLoadWithRequest is never triggered. DocumentWebBrowserDidStartLoad is triggered, but I didn't find a way to stop the browser to stop the navigation. I tried calling Stop, FinishLoading and FailLoadingWithError without success. Any way to achieve this (without using CEF4)?

Related

Is there a way to dismiss a native authentication dialog when using Playwright?

I'm using Playwright (Java) to drive a particular third-party Web site, the first page of which apparently containing two images which are password protected; this causes a sequence of basic-authentication dialogs to open when the page loads.
I'd like the script to dismiss these dialogs (cancel), rather than providing any credentials, and then continue working with the page. But as it stands now, the page.navigate() blocks and eventually times out, unless I cancel these dialogs manually with the mouse.
Note that this is the native browser dialog, not anything generated from js on the page.
Is this possible with Playwright?
Interestingly, I was able to work around this by disabling images entirely in Chrome, which might have other (performance) benefits, too.
Added this to the array of Chrome startup arguments:
--blink-settings=imagesEnabled=false
Of course, this only solved this specific case, in which the login prompts were being triggered by image URLs.

Phonegap Tabbar. When window.open is called, TabBar loses functionality

I am relatively new to the world of JS and Phone Gap. I am using the Native TabBar plugin on my app which is working perfectly however when one of my tabs calls:
function TabPressed(){
window.open('www.google.com', '_self', 'location=no');
}
My TabBar loses its functionality. I guess this is because the window.open is opening a new webpage with new js etc... how do I still allow my tabBar to function when a new window is opened.
using window.open you are loading a new page, leaving the old page completely(with scripts and styles), so the listeners that you attached to TabBar are gone.
You should keep this code available at all times. If you need to load external web pages, load them using ChildBrowser plugin.
Or have a local page(index.html) and include all phonegap related scripts in this page. When you need to open a new page, use ajax and insert the html into a container div in this already loaded page. Most of Phonegap applications use this approach.

How can I load iOS webclip links in the same window?

After loading up a Webclip with some links in it, clicking a link launches Mobile Safari instead of loading the link in the same window. Is there a way to prevent the link loading in Safari instead of the Webclip instance? I'm trying to mock up a mobile app just using PHP on my local Apache installation.
According to the Apple docs it looks like external page links will always open in Mobile Safari:
In this mode any external links will be opened in Safari on
iPhone, meaning that you will have to keep your web application to a
single page and use Ajax to update parts of that page.
In addition to the option of using a single page loading new content with AJAX, you can use the JavaScript self.location=URL; return false on hyperlinks that must stay within the application. This can be added to the HTML code directly, or with another script upon loading the page.
If you are using jQuery, I would recommend something like this:
$('a:not([target])').click(function(){
self.location = $(this).attr('href');
return false;
});
Obviously this script should be ran after the HTML has loaded, to ensure that it actually attaches to the A elements onClick event.

Prevent Java Applet from gaining Focus

An applet gains focus when loaded, preventing browser keystrokes from working. You can work around this by adding a parameter to the applet tag:
name="initial_focus" value="false"
So far so good. But when the user clicks on the applet even if the applet does not have any user interface controls, then the problem remains.
I guess another way to phrase the question is: How can I get the applet to forward all keystrokes back to the browser?
You can attach a button click handler to the parts of your application that doesn't have a UI (for example your root pane), and execute a piece of javascript code that will be run by the browser, delegating the focus to some HTML DOM element instead.

Jquery load external file that relies on jquery plugin

I have a set of jqueryui tabs that, when clicked, load in their content dynamically. It works great, except that one of the pages uses a jquery plugin itself. This results in two issues:
The main page that holds the tabs throws an error when loaded because there is js that refers to elements that haven't loaded yet (those elements are in the external file that contains the code that relies on the plugin).
If I embed the js that triggers the plugin functionality into the external file, it is outside of the document.ready function from the main page and therefore isn't usable.
Basically I am looking for a technique that allows me to ajax load an external html file into the DOM while not crapping out the main page itself because JS that is already there is expecting HTML which is not yet there.
Thanks.
I haven't used it yet, but I think that this is what you are looking for
Listen
This plugin brings a clean, light solution, to websites with dynamic loaded content, or full of event bindings.
Intead of bound, handlers for events, are registered along with matching selectors.
And they'll still work for new added content.
This is achieved, using Event delegation, so the plugin will only work for events that bubble
You need to encapsulate your jquery code inside of the $(document).ready() function. If you're saying the code that's waiting to load via AJAX may or may not be loading at the same time as the parent page (i.e. a user has to click the tab to load it, vs. it being the default load) then you're design is bad and you'll have to rethink the approach. Basically you can't have code in your parent page referencing DOM elements that don't yet exist, and may not exist until your user clicks a tab.

Resources