simulating .click() for non http urls - javascript

I have taken up a rather ambitious task.
Scenario:
A user gets a sms on his mobile. The sms is basically an alert. I want the user to be able to share the message to his whatsapp contacts by clicking on a link rather that he copying the messaging, opening whatsapp, selecting a contact, pasting the message and clicking on send.
If a website has html tag written in the following way:
<a id="blood-request-sms" href="whatsapp://send?text=Hello%20World!">
B+ required by 21st March at Hyderabad
</a>
and the user clicks on the link on a mobile browser, whatsapp opens and allows the user to select the contact / group and sends the message (Hello World! in this case)
Since I don't want the user to click more than once till he opens whatsapp to select the contact/group I thought of a design like this:
a) The user gets a sms with a url like goo.gl/qpdRdr
b) This opens a page for which I have written the following code on load of the page
document.getElementById('blood-request-sms').click();
This ideally simulates the click on the a element and should open whatsapp.
This working for any href of http protocol but for whatsapp, this is not happening.
Any way I can get this working??
Thanks,
Lakshman.

Your provided example does actually work on my device (iPhone with iOS 9).
Maybe you could also try to skip the aaltogether and just assign a new location.href:
<a id="blood-request-sms" href="whatsapp://send?text=Hello%20World!">
B+ required by 21st March at Hyderabad
</a>
<script>
location.href = "whatsapp://send?text=Hello%20World!";
</script>

Related

How to deep link to an app without asking user?

There is a website called url genius.
How it works: you choose Instagram for example, you write your profile link, and then it creates a deep link, when you click on it either you're on iPhone or Android, it open directly the app WITHOUT ASKING "DO YOU WANT TO OPEN THIS LINK IN THE APP"
I tried to replicate this with some JS, my code first detect which device the user is on, then :
if the user is on Android it redirects with a window.location.replace to intent://www.instagram.com/profile/#Intent;package=com.instagram.android;scheme=https;end
if the user is on iPhone it redirects with a window.location.replace to instagram://user?username=profile
MY PROBLEM:
The link doesn't open directly in the app, it first asks to the user "do you want to open the link Instagram app". So how does URL Genius manage to redirect directly the user?

How to hide URL link on hover in Outlook

I've made a email template in HTML for Outlook and it includes a button, when the user clicks the button it navigates to a website. I'm trying to hide the URL link when the user hovers over it.
When I test the template using Google Chrome the URL doesn't appear and when you click on the button it goes to the website but when I send the template in Outlook, you can't see the link when you hover over it but when I click on the button it doesn't go to the website.
I'm fairly new at this, so was wondering it anyone could help. The code I'm currently using is:
<a onclick="location.href='IP Address'">Click here</a>
This is impossible (thankfully, since support for this would be a great boon to phishers).
Email clients that accept HTML formatted mail do not accept JavaScript.

How do you set a registration form email link to open the link in the original browser tab?

I set up a registration system which requires clicking on a link in email to confirm/activate the account. It looks like:
$textContent .= "Dear John,\n\n
Thank you for registering with YourBusinessName.
To complete registration click on the activation link:
\n\n
<a href='https://www.your-website.abc/activate-account' target='_blank'>activate</a>";
This works however when you click on the email link it always opens in a new browser tab (or window depending on preferences). This leaves a confusing extra, lame, window in a tab.
How do you make it either open in the original tab/window or perhaps open while simultaneously killing the original tab?
Just remove target attribute from your link:
<a href='https://www.your-website.abc/activate-account'>activate</a>";
Or set it to target="_self":
activate";
Specification of the attribute: https://www.w3schools.com/tags/att_a_target.asp
Sometimes you get a problem to solve in your head and you fail to see the obvious. The core problem is to keep from having new windows open when attempting to confirm a registration form.
The answer is to provide a confirmation code in the email message rather than a link and instruct the visitor to copy the code into the confirmation page on the screen.

iOS 12 Shortcut Setup Question for "Run JavaScript on Web Page"

I'm hoping this is the right place for this question since it centers around JavaScript. In the new iOS 12 Shortcuts app you can create workflows. I want to create one that simply launches a web page, fills in my username and password, then clicks the submit button, something like this...
document.myForm.username.value = 'myUsername';
document.myForm.password.value = 'myPassword';
document.getElementById('loginSubmit').submit();
But before even getting that far I just want to run an alert(1);. I can't get that to happen. I keep getting this error message below...
Run JavaScript on Web Page failed because Shortcuts couldn't convert
from URL to Safari web page.
I'm not sure what that means. I haven't been able to find info or tutorials on how to use this. Does anyone know how to get JavaScript to run? Thanks!
the first thing you need to know is that docs are here: https://support.apple.com/guide/shortcuts/welcome/ios
Now, the problem is that "Run Javascript on web page" need an input called "Safari web pages" but Open urls only gives as output the result of opening the url that is showing the page in safari, in order to make it work you need Open url to give you a "Safari web page" item.
The only way that I found to do that is to use the shortcut as a "Share extension"
In your workflow delete the URL item
Go to the shortcut settings page by tapping the icon
Settings icon
Now tap on "Show in Share Sheet"
In the "Accepted types" section, select only URLs that is at the very bottom of the list.
Finally go to safari, open the url you want and tap the share button, if this is the first time you do this, you need to active the "Shortcuts" section, in the bottom list go to the end and tap in "More", the scroll down and select "Shortcuts"
After doing that you will have the Shortcuts option, tap on it and select your Shortcut and it will run the java script in the page.
Is important to note that you will need to do something with the output of "Run javascript on web pages" like showing the result in one alert, because the way you have your workflow now, it may look like nothing is happening.
There's a note in the Run JavaScript on Web Page action that says, "Safari Web Page item in shortcuts stating that they are only available when running your shortcut as an Action Extension in Safari."
So, sadly, it's not possible to chain up actions where it launches a URL and then runs JS. You must visit the url and run the action from the share sheet.
The Safari actions require Safari to be open to the page you want when you launch the activity. That said, you can accomplish this easily using another element.
I don’t know your technical level, so I apologize if any of this is stuff you already know, but for you and for future reference to anyone looking, here is the howto.
First, go to the page you want on a Mac/PC browser and open the developer tools. I use Firefox Developer Edition, but Safari and Chrome have them also. If you’re using MacOS Safari, you will first need to open Safari’s Preferences menu and check “developer options” and relaunch.
Once the developer tools are open, switch to the Network tab / pane; find and turn off the option which clears the log on each page load. Keep this pane open, fill out the form, hit the trash can to clear the network log, and then submit the form. Now the HTTP request of the form submission should be either the first or the only thing in the list.
Select the line for the form submission and look at the request header. There should be a Request Method, Request Url, and all the key-value pairs that were submitted with the form.
Back in the Shortcuts app, add a URL element and give it the same URL as the Request Url. Chain this URL input element to a Get Contents of URL action element and toggle open the Advanced drawer. If there are any additional headers in the request log, you can tap Add new header to add more. Match the Request-Type to the Method field, choose “Form” as the Request Body, and then add in all the keys and values from the request.
Anyways, that’s it.
Chain this to Set Variable then use an IF block to test if the login succeeded or not. If it succeeded, make a Show Result that says “You are now logged in.” and if it failed, show the variable so that you can debug the response.
For API requests in shortcuts, I typically use the Get Contents of URL shortcut, which allows you to use different HTTP methods (POST, GET, etc) and adjust the URL parameters.
In your case, once you authenticate, you could use the authentication token to make other requests as needed.
View Apple's documentation here for an example

WIndow.name not setting window name in a way that target identifies

My use case:
User already has web app open in a browser tab
An email is sent to the user with an anchor tag that takes user to a specific page in the web app
On clicking, the initial tab is repopulated with new page
To do this the anchor tag is formatted like <a target="webapp" href="example.com" >Click Here</a> and I have a tiny bit of javascript, triggered on load, in my web app like this window.name="webapp"
What is working:
If I test to make sure the window name was with window.name="webapp", doing console.log(window.name), it confirms that it was
If I click the link from the email and the web app isn't open yet a new tab opens. If I click that link again the tab that initially opened refreshes.
What isn't work:
If the user initially navigates directly to the web app (not via a link) and then clicks the link from the email, the link opens a new tab instead of repopulating the open tab. In this scenario I still get the correct window name in the console log but not the functionality I'm looking for.
Looking for insight into how to get this to work or if there's a better solution to this use case.

Categories

Resources