when i open a url using inappbrowser it doesn't open - javascript

When i try to open a url in android using inappbrowser, the url does not open a shows a blank screen with the url on the top. But when i try to open the same url in chrome it is opening fine and also on ios device it is working fine.
Issue only comes when opening in android inappbrowser.
Is it some javscript issue or something else, i m not able to figure it out.
this is the code which opens the url:
const browser =
this.iab.create('loginDetails.serverURL','_blank','location=yes,toolbar=yes');

you can use this..
String link=URL_LINK;
if (!link.startsWith("http://") && !link.startsWith("https://")){
link = "http://" + link;
}
Uri uri = Uri.parse(link); // missing 'http://' will cause crashed
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
context.startActivity(intent);

Related

URI schema does not work on iOS google chrome app

I would like to create a web-page, a page that will redirect to App Store if App is not installed in iPhone, and will redirect to The App if App is installed in iPhone.
I wrote Javascript like below.
function launchApp(){
let URI_SCHEME = 'myapp://';
let APP_STORE_URL = 'https://itunes.apple.com/jp/app/myapp/id111111111';
let userAgent = navigator.userAgent.toLowerCase();
if(userAgent.search(/iphone|ipad|ipod/) > -1){
location.href = URI_SCHEME;
setTimeout(function (){
let aTag = document.createElement('a');
aTag.href = APP_STORE_URL;
aTag.Click();
}, 1200)
}
}
I tried this code, and in iOS Safari, it works as I expected.
However, in iOS Chrome app, it does not work.
To be more specific, when I tap the link button to the page that I am creating, the new tab opens but closes immediately.
Does anyone know why it does not work in iOS Chrome app?
Moreover, does anyone know better solution?
Thank you for your cooperation.

How to redirect apps from browser to safari?

How to redirect apps from browser to safari?
on android, I do this if a user opens my site through a browser built-in for example in FB or a Telegram, then he immediately redirects to google chrome where my site opens
Location: googlechrome: // navigate? Url = $ url
how to do the same on ios you just threw on safari?
you can do this with a deep link
you go to the properties Xcode and add a associated domains:
for example applinks:flink.page.link <-(flink.page.link should be your url)
then in the appDelegate put this
func application(_ application: UIApplication, continue userActivity: NSUserActivity,
restorationHandler: #escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
if let incomingURL = userActivity.webpageURL {
//open a view or something else
}
return false
}
for more information use this : ios deep link

Download S3 file from pre-signed URL without popup blocker

I have a Meteor application where I'm downloading files from S3 using pre-signed URLs (need to be generated with an API call).
I was having an issue with popup blockers preventing a new tab from opening with the url generated by the AWS-SDK so I changed my code to the following:
downloadDocument(document, event) {
// open tab immediately to prevent popup blocker
const myNewTab = window.open();
// call method to generate url
Meteor.call('Events.Methods.Document.Download', { key: document.key, eventId: event._id }, (error, res) => {
if (error) { ... } // removed handle error code
// if url generated, set tab location to url
if (res) myNewTab.location.href = res;
// auto close the tab after 1 second
myNewTab.setTimeout(() => { myNewTab.close(); }, 1000);
});
}
This code is working for the most part but it doesn't feel very clean. Also if the API call ever takes more than 1 second (slow internet) then the tab will close before the download begins
How can I change this so that I can wait for the download to happen, before closing the tab? Or a similar solution that would result in me ensuring the downloads always go through without popup blockers being an issue?
Thanks
You are always going to run afoul of pop-up blockers if you open a new window.
What you should do is generate an <a href="my-custom-server-generated-url" download> link with the download property, which will force a download without needing a new window.
Then you also don't need to close the window on a timer (which wasn't a good approach in the first place)
This was happening only in Safari, so we switched to always downloading the file instead of opening in a new window in Safari/mobile.

Opening a new tab using Ctrl + click combination in Selenium Webdriver

I am attempting to use ctrl + click on a link to open it in a new tab. This is working fine in Chrome 58. Please find the code below:
action.keyDown(Keys.CONTROL).click(driver.findElement(By.xpath
("//section[#class='filmStrip__basic']//a[text()='En savoir
plus']"))).keyUp(Keys.CONTROL).build().perform();
I am using the same code on IE, Firefox and Safari but getting the following error:
Firefox 54: The link is getting open in the same tab.
IE 11: Nothing happening.. the control is moving to the next line
Safari: exception on action.keyDown-Unrecognized command
Help related to any one browser is also appreciated.
Thanks
As you are trying to click on a link which is within a <a> tag, instead of xpath you can use the linkText locator. Here is the sample code with opens the url http://www.google.com, verifies the Page Title, uses Actions class to click on the Gmail link to open https://accounts.google.com in a new tab.
String URL="http://www.google.com";
System.setProperty("webdriver.gecko.driver", "C:\\Utility\\BrowserDrivers\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get(URL);
System.out.println("Page Title is : "+driver.getTitle());
WebElement link = driver.findElement(By.linkText("Gmail"));
Actions newTab = new Actions(driver);
newTab.keyDown(Keys.CONTROL).click(link).keyUp(Keys.CONTROL).build().perform();
You can find a relevant Python based solution in How to open a link embed in web element in the main tab, in a new tab of the same window using Selenium Webdriver
Another way is to use javascript executor:
JavascriptExecutor jse = (JavascriptExecutor) driver;
jse.executeScript("window.open('','_blank');");
As for your problem I had it too and didn't find anything usefull until I found this workaround.
I even tried: solution with ctrl + enter
try this way....
// specify chromedriver.exe directory path and replace in "driverPath"
String driverPath = "C:/Users......";
WebDriver driver;
System.setProperty("webdriver.chrome.driver", driverPath + "chromedriver.exe");
driver = new ChromeDriver();
System.out.println("lanuching 1st url in tab1");
driver.navigate().to(
"https://amazon.com");
System.out.println("lanuched 1st url in tab1");
Thread.sleep(30000);
((JavascriptExecutor) driver).executeScript(
"window.open('http://ebay.com');");
Thread.sleep(20000);
Set<String> allwh = driver.getWindowHandles();
System.out.println(allwh.size());
for (String v : allwh) {
System.out.println(v);
driver.switchTo().window(v);
String title = driver.getTitle();
System.out.println("2nd url in tab2" + title);

using a redirect to launch an app and still stay in same page in asp.net

I have written a website that uses bankid authentication, I don't know how common this is outside of sweden, but basically it is either an app in the mobile phone, or a local software in windows. to launch the application in windows a redirect needs to be made that looks like this:
if (startLocalApp)
{
Response.Redirect("bankid:///?autostarttoken=" + AuthResp.AuthenticateResponse1.AutoStartToken + "&redirect=" + Request.Url.AbsoluteUri);
}
the problem with this though is that the redirect of the software does not work the way I need it to work since the redirect it does opens a new tab with the web page I need to get back to in a new tab, and the session variable is all messed up. so what I need to do is the opposite, launch the app in a new tab, and let it close the tab when it's done, since I have all references needed before I've launched the app it does not need to be executed in the same browser window even.
so how to make the redirect in another tab, and is it possible to keep executing code after the redirect? if not, I need to make a post back to continue execution of the code-behind.
edit:
I've tried one solution, it feels like I'm getting closer but I'm not quite there yet.
front-end:
<script type="text/javascript">
function StartBankIdApp(){
var _url = 'bankid:///?autostarttoken=<%= (AuthResp == null || AuthResp.AuthenticateResponse1 == null) ? "null" : AuthResp.AuthenticateResponse1.AutoStartToken %>&redirect=null';
var $irWin = window.open(_url, '_blank');
if ($irWin != null) {
$irWin.close();
}
}
</script>
code-behind:
if (startLocalApp)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), StartBankIdApp", "StartBankIdApp()", true);
}
the app is not launched, i.e the window it should open does not open.
did I do something wrong?
I think you are trying to use "URL scheme" to launch an app. And that you want that the app should be triggered in a new tab (or window).
This can be achieved through javascript. To open any link in new tab we can use window.open and set target attribute as _blank. Here is a sample code
var _url = 'app:MyApp?queryString=somestring';
var $irWin = window.open(_url, '_blank');
if ($irWin != null) {
$irWin.close();
}
What I've done here is that after launching the app I've closed the new tab (or window).
The javaScript code would continue to run (that is it will not wait for the app to complete the process).

Categories