Webview Link Controls for Cocoa App - javascript

Is there a way to control links in webview? The scenario is dealing with external protocol links such as mailto://, irc://, target=_blank, and anything else that may provoke a launch of a new window or app. Maybe it would pop up an nsrunalert saying that 'External links has been disabled'. Would this be something that javascript would handle or some functions within webview itself?
Thanks for any suggestions

You need to set yourself up as a WebResourceLoadDelegate and implement webView:resource:willSendRequest:redirectResponse:fromDataSource:
See http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/WebKit/Protocols/WebResourceLoadDelegate_Protocol/Reference/Reference.html#//apple_ref/doc/uid/TP40003836 for more info.

Implement what buts of the WebPolicyDelegate you need. All navigation goes through there

Related

How to hide URL Bar in Ionic 5 Capacitor using Browser Plugin?

Checking the new Ionic Capacitor Docs, there seems NO OPTION to hide the url bar of the Browser Plugin (Previously InAppBrowser) at the moment. Need help please.
According to this discussion on a GitHub Issue thread, this is not going to be possible due to the fact that both the IAB and Browser plugins use SFSafariViewController, which doesn't allow you to hide the native controls.
That said, this has been driving me crazy for a while now, as I can't hide the URL bar in either OS even when using the original IAB.
I use iframe to solve the problem
<iframe src='https://stackoverflow.com/' />
ps: url use https

Opening safari webpage from Cordova app

I'm working on an APP that consist of HTML and CSS using the Cordova framework.
There is a button that should open a webpage. The problem is that it opens the webpage inside of the app instead of safari.
My knowledge of Objective C is extremely limited (none) so I was hoping there would be a solution using maybe Javascript.
I've looked all over the internet but couldn't find a non-Objective C solution.
The button is pretty straightforward: <img src="img/button.jpg" alt="website">
I thought target="_blank" might do something for me but that (unsurprisingly) didn't work.
You can use inappbrowser plugin
http://cordova.apache.org/docs/en/3.3.0/cordova_inappbrowser_inappbrowser.md.html#InAppBrowser
Detect click on link using javascript or jquery and use this following code
window.open('http://www.google.com', '_system', 'location=yes');
I found the answer to my problem:
Opening all URL's with Cordova childbrowser
Only problem is that it automatically opens twitter.com because of the share button for some unknown reason. I'm guessing this is because of an api call it's performing upon being loaded.

Working bookmark script for iphone/smartphones

Can you use a script on your page with the "bookmark us" url on a smartphone? I know Chrome doesn't support this function but i was wondering if there is a way to get it working on an iphone?
Cheers,
Toby
As far as I know, there is unfortunately no way to do this in code on iOS.
The suggested route is to prompt the user to add your website as a bookmark.
To do this, there is a neat little JS library: mobile-bookmark-bubble.

IE and Selenium: window.createPopup()

I've been playing with Selenium lately, trying to create tests for an IE only application. Things were progressing (though slowly as without the recorder plugin I had to resort to trial and error to try to find the appropriate element paths), but now I'm stuck with a problem related to popup menues.
Most of the application actions are triggered from a popup menu created with javascript window.createPopup() and I can't seem to find a way to send events to elements inside the popup.
Maybe I should be selecting the popup like I do for windows opened with window.open(...), which are working fine BTW. I tried assigning a name to the popup menu returned by createPopup() and treating it the same way I treat windows but that doesn't seem to be working.
Does anybody knows if this is supposed to work? Any help will be appreciated.
Thanks,
Unfortunately, no. window.createPopup isn't accessible to Selenium. Being an IE only feature it has really limited portability and generally isn't a best practice. I know that's of little consolation to you, because I assume your stuck with someone else's code that's used createPopup.
The real problem is that craeatePopup doesn't add anything to the DOM. Try opening a popup object and viewing it's source. You'll see this:
<html><body></body></html>
So there's nothing really there for Selenium to grab hold of.
What does the popup do for your application? You indicated it provides some navigation, can you just navigate to those pages directly?
if you know the name of the window you can do
selenium.click("elementToLaunchPopup");
selenium.waitForPopup("nameOfWindow",30000);
selenium.selectWindow("nameOfWindow");
// rest of your test
To get back to the main window you will need to selenium.selectWindow("null");
I am using selenium 2.0b3 with InternetExplorerDriver. I found something that do the trick.
In your js save a reference to the popup window.
var popUp= window.createPopup();
Then in your java code:
public Object executeJS(String code){
JavascriptExecutor js = (JavascriptExecutor) driver;
return js.executeScript(code);
}
WebElement popUp =(WebElement)
executeJS("return popUp.document.documentElement;");
This will give you a reference to the page and you can find elements normally.

Simple dashboard application

I am trying to have some fun with dashboard widgets, so I tried a simple application :
There will be a button over the widget which when clicked will open
StackOverflow website in safari.
To implement it, I tried this:
Created a custom dashboard widget.
Added a button to it from library.
Associated gotoStackOverflow handler with onclick event.
in body of function gotoStackOverflow, I wrote this code:
window.open('https://stackoverflow.com/','Stackoverflow','width=400, height=300');
When I 'Run' the application I found no browser window appearing on click of the button.
Can anyone suggest me where I may be wrong or/ and some useful links to play with dashcode and dashboard widgets?
Your code runs fine, when I recreate it. Maybe you have pop-ups blocked in Safari?
have you added
<key>AllowNetworkAccess</key>
<true/>
to the plist? if not the outside world will not be available.
I have used following code to solve my problem:
function gotoStackOverflow(event)
{
widget.openURL("http://stackoverflow.com/");
}
cheers... :)
Miraaj

Categories

Resources