tel: links from UIWebView - uiwebview

I opened tel: links in UIWebView through the following two methods。
1、
<script type="text/javascript">
function call(){
window.location.href="tel://10086"
}
</script>
<button type="button" onClick="call()">call 10086</button>
2、
href 10086
When I do not implement any UIWebView Delegate Methods, both methods work well. But when implement shouldStartLoadWithRequest and return YES, such as:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
return YES;
}
the first method does not work, and error:
Error Domain=WebKitErrorDomain Code=101 "The URL can’t be shown" UserInfo=0x15b4f0
{NSErrorFailingURLKey=tel://10086, NSErrorFailingURLStringKey=tel://10086,
NSLocalizedDescription=The URL can’t be shown}
the second well. Why?

Related

How to display external links content in a dialog from Java Bean? [duplicate]

This question already has an answer here:
JSF tag that load HTML from external source
(1 answer)
Closed 3 years ago.
I should display an external link content in a dialog dynamically.
I trayed this in my bean but it just opens a new tab.
Is there any other way to show the content of the external link in the dialog?
I use Primefaces, Trinidad, and JSF in my pages and am open to using any other framework.
Any simple solution is very welcome.
in bean:
public void launchUrl(String url) {
try {
FacesContext.getCurrentInstance().getExternalContext().redirect(url);
} catch (IOException e) {
e.printStackTrace();
}
}
in xhtml:
first method:
<tr:goButton id="evsButton1" text="eVS" onclick="openUrl('#{bean.url}')" />
<script type="text/javascript">
function openUrl(url) {
window.open(url,"_blank");
}
</script>
second method:
<tr:goButton id="evsButton" text="eVS" destination="#{bean.url}" targetFrame="_blank" attributeChangeListener="#{wijzigBean.fetchUrl}" />
I think it should be possible to add the external content as an iframe
<div id="someId">
<iframe id="iframeId" name="iframe" frameborder="0" scrolling="auto" src="#{yourbean.externalUrl}">
<p>Something went wrong.</p>
</iframe>
</div>
from Adding iframe to JSF components

iOS7 UIWebivew Youtube MPMediaPlayer not working

I need to play a video within an UIWebiview which comes from youtube.
Everything was working fine on older devices (5.1+)
Unfortunately on iOS7 the video is not playing. It starts loading but it'll never start playing. Even if the video has fully been loaded. Only if you stop and press play manually the video starts playing.
Here's some code:
- (void)viewDidAppear:(BOOL)animated;
{
[super viewDidAppear:animated];
if(!self.viewMoviePlayerView.superview) {
[self.viewMediaContentContainer addSubview:self.viewMoviePlayerView];
}
self.viewMoviePlayerView.isScrollingEnabled = NO;
[self.viewMoviePlayerView loadRequest:[NSURLRequest requestWithURL:
[NSURL URLWithString:
[NSString stringWithFormat:#"%#%#", #"http://www.youtube.com/embed/", self.currentSelectedItem.guid]]]];
...
}
Any suggestions on that?
Autoplay is not allowed on recent versions of iOS. You don't suppose to programmatically start downloading data that could cause a cost to the user. I found a way but it's a little tricky:
Show an html string in stead of an url
[webview loadHTMLString:<html> baseURL:[[NSBundle mainBundle] resourceURL]];
The html needs to be an embed player:
<html>
<body style='margin:0px;padding:0px;'>
<script type='text/javascript' src="http://www.youtube.com/iframe_api"></script>
<script type='text/javascript'>
function onYouTubeIframeAPIReady(){
ytplayer=new YT.Player('playerID',{events:{onReady:onPlayerReady, onStateChange:onPlayerStateChange}});
}
function onPlayerReady(a){ a.target.playVideo(); }
function onPlayerStateChange(event) {
if (event.data == YT.PlayerState.BUFFERING) {
event.target.playVideo();
}
}
</script>
<iframe id='playerID' type='text/html' width='320' height='240'
src="http://www.youtube.com/embed/xxxxxxxxxxx?enablejsapi=1&rel=0&playsinline=1&autoplay=1" frameborder='0'></iframe>
</body>
</html>
this works fine because the javascript in the iframe API it forces the player to start playing once it loads and every time it starts buffering. I strongly suggest you to read about the youtube API
Put your video id in the embed and thats it!

Dijit.MenuItem and <a href=></a> link

My question is similar to that one:
Dijit Menu (bar) with link
I'm using Dijit Menu as in following listing:
<div data-dojo-type="dijit/Menu">
<div id="menuItem" data-dojo-type="dijit/MenuItem">
urlLink
</div>
</div>
But link is not working as it blocked by dojo.stopEvent in _onClick().
The question is:
How to remove dojo.stopEvent and make link inside <div id="menuItem" data-dojo-type="dijit/MenuItem"> work properly?
The issue:
I need to put inside <div id=menuItem"> some code, which has to receive onClick event.
P.S. Originally this is XPages code.
Well I fell in same problem, saw this post and the related other, but wasn't satisfied with the "onclick" solution :
it didn't work (for me) with keyboard navigation
it imposes to a add script element (onclick=...) in the declarative zone which is not what I expect for unobtrusive JavaScript
Finaly I digged further in dojo and decided to directly use the href attribute of first sub-node in the handler. My script section (derived from dijit menus tutorial) is then :
<script>
require([
"dojo/dom",
"dojo/parser",
"dojo/dom-attr",
"dojo/query",
"dijit/registry",
"dijit/WidgetSet", // for registry.byClass
"dijit/Menu",
"dijit/MenuItem",
"dijit/MenuBar",
"dijit/MenuBarItem",
"dijit/PopupMenuBarItem",
"dojo/domReady!"
], function(dom, parser, domattr, query, registry){
// a menu item selection handler
var onItemSelect = function(event){
dom.byId("lastSelected").innerHTML = this.get("label");
var achild = query("a", this.domNode)[0];
if (achild != null) {
var href = domattr.get(achild, "href");
if ((href != null) && (href != '') && (href != '#')) {
window.location.href = href;
}
}
};
parser.parse();
var setClickHandler = function(item){
item.on("click", onItemSelect);
};
registry.byClass("dijit.MenuItem").forEach(setClickHandler);
registry.byClass("dijit.MenuBarItem").forEach(setClickHandler);
});
</script>
That way I don't have to change anything in a menu of type
<ul><li>...</li></ul>
that works with JavaScript disabled, and links work fine with mouse and keyboard navigation when JavaScript is enabled. Simply don't forget the "class='claro'" in body element ....
What about this:
<div data-dojo-type="dijit/Menu">
<div id="menuItem" data-dojo-type="dijit/MenuItem"
onclick="window.location('http://url.com')">
urlLink
</div>
</div>
Working jsfiddle:
http://jsfiddle.net/KuyYX/

how can i fire up contentscript

i got a simple question
i have these3 files
popup.html :
<script>
function buttonClicked(button)
{
chrome.extension.sendRequest({command:button.id});
}
</script>
<input style="width:100%" type="button" value="Click me" id="click" onclick="buttonClicked(this)"/><br/>
background.html :
<script>
function processRequest(request, sender, sendResponse)
{
alert('hi');
sendResponse({});
}
chrome.extension.onRequest.addListener(processRequest);
</script>
and contentscript.js
s = document.getElementsByClassName('st');
if (s[0].innerText != '') {
st = new Array();
for (i = 0;i<s.length;i++) {
st[i] = s[i].innerText;
}
chrome.extension.sendMessage({"message" : st}, function(response) {});
}
i would like to fire up the contentscript each time i click on the button in the popup page be cause somehow the script in the contentscript dosnt work neither or background.html nor on popup.html?
thank you
I've attempted to explain the solution and why to use it in the comments, three times. Since you don't understand it, I'll explain it again with references to your code:
Popup
Move the inline script to an external file, say popup.js.
Delete the inline event listener, and also move it to popup.js.
popup.js
function buttonClicked(button) {
chrome.extension.sendRequest({command: button.id});
}
document.getElementById('click').addEventListener('click', function() {
buttonClicked(this);
});
popup.html
<script src="popup.js"></script>
<input style="width:100%" type="button" value="Click me" id="click"><br>
If you test the previous code, you'll notice that it does not work. That's because the contents of popup.js is executed before the button (which occurs after the <script src> is created. This can be solved in two ways (use either method, but not both):
Recommended: Place <script src="popup.js"></script> before the closing </body> tag in popup.html. Then, you're certain that all elements do exist when the script is executed.
Alternative: Wrap the event listener call in a DOMContentLoaded event:
document.addEventListener('DOMContentLoaded', function() {
document.getElementByUd('click').addEventListener( ... );
});
Background page.
For a more thorough explanation on the available options, see the middle of this answer.
Modify the manifest file, use "background": {"scripts": ["background.js"]}.
Rename background.html to background.js, and remove <script> and </script> from the file.

How to implement event handling in uiwebview?

I have taken a webview to show some HTML content in iPhone. Now I want to put some action on user events on the phone. I want to trace the tap event done on the screen by the user on that web view.
For this I have added a method
-(void) touchesBegan: (NSSet *) touches withEvent: (UIEvent *) event {
in my code.
But the problem is when I click outside the webview it works perfectly. Bt when I tap on the web view, it does not respond. So, please tell me what should I do to acheive tap event trace on that particular web view.
Help me out.
- (BOOL)webView:(UIWebView *)wv shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
NSURL *url = request.URL;
if ([[url lastPathComponent] isEqual:#"testmessage"]) {
NSLog(#"Nya");
return NO;
}
return YES;
}
HTML
<a href='testmessage'>Test</a>
or
<script>
function callObjc(){
document.location = 'testmessage';
}
</script>
<a onclick='callObjc();'>Test</a>

Resources