I was wondering if there is a way to retrieve the URL scheme of a browser application using javascript (on mobile)?
For example:
You're browsing a web page on your phone using Google Chrome. Would it be possible for that page to run some javascript and retrieve the googlechrome:// scheme?
Thanks!
Edit:
I just found out that the 'navigator' object has a method called 'registerProtocolHandler' which lets websites register themselves as possible handlers for particular protocols.
This comes pretty close to what I need. The only problem is that this requires permission from the person who is visiting the website, which doesn't compliment the flow I'm going for. Also, it doesn't support Safari on iOS..
By the time your JavaScript is running on the webpage, the user's phone has used the URI Scheme (say googlechrome://) to choose a web browser it has installed. The browser then requests your site using a web protocol like http://. This is what window.location.protocol will provide.
So, JavaScript isn't aware of 'schemes' in the sense of 'browser applications'.
However, you can figure out the user's browser from their User Agent and then deduce a possible URI scheme from this. Still, you can't be certain the user didn't just open up Chrome and navigate to your site themselves, without ever tapping a link.
Note that user agents are not always reliable:
users of a browser can change the value of this field if they want (UA spoofing).
Related
I have a web page, where i would like to add links using a custom protocol, to open in my desktop application. For example "myprotocol:www.mytestpage.com".
My issue is, how do I detect, using javascript, if the user has registered my protocol?
If for example I use the link above in firefox, withouth having the protocol registered, I am just taken to an error page. Instead I want to show a dialog telling the user to download my application.
As far as I know you cannot tell whether the protocol has been registered or not.
This answer should give you a step in the right direction. https://stackoverflow.com/a/24129863/7326037
if there is a web page which will be inserted into an app, it can be linked to another page within an app when I click somewhere on the web page because of the special link that can only be open within an app. However, if I want to make the same web page be opened within a mobile browser, I have to replace the special link.So,the prerequisite is that I need to detect if the web page is opened within an app or a mobile browser. Anyone can help?
1) Try to read the User Agent header from the http connections headers. It will show you the device that is connecting to your site. (proud to be hacked since header can be changed)
Here you have a php example on how to read user agent
<?php echo $_SERVER['HTTP_USER_AGENT']; ?>
2) Add some logic on your app and on your web page in order to "recognize" each other.
A simple logic could be to add a parameter read on your web page that must have an specific value in order to allow access. Your app must call the url with the expected value on it parameter.
What you're looking for is the user-agent, each browser has a different user agent (name) which generally tells you what sort of device the browser is built for.
There are plenty of ways of retrieving the user agent with javascript check this previous StackOverflow question + answer here.
You can check the browser's useragent, which is a string. MDN
You can access it via Javascript and then perform conditionals based upon the result.
All browsers will return something slightly different so you will need to find something common to reduce the number of branches.
if(window.navigator.userAgent.match(/Android/i) {
//Android browser, do something
}
Bunch of strings here: UserAgent strings
I'm not very familiar with browser extensions and before I begin to deeply explore them I have a few questions.
Let's say the extension injects JavaScript in the current website the user is visiting (if that's even possible). That injected JavaScript code will get, let's say the current URL for example purposes, and send it and store it on a database. Next time the user visits the same website, the user will get an extension notification informing that is the second or third or X time he or she has visited the same website.
Now that I have gave you the scenario, is the following possible? Injecting JavaScript from a browser extension to the current visiting website. If so, can I make some AJAX communication with the JavaScript and a PHP server?
Yes, you can inject stuff. See e.g. Insert code into the page context using a content script and How to inject javascript into page, from a Firefox add-on, and run it? or one of the many dupes there likely are.
You can then use whatever communication would be available between the site and a server, e.g. XHR, WebSockets, JSONP.
Please also check the policies of the Chrome Web Store and Mozilla Add-ons site regarding content/code injection and privacy rules. E.g. the Mozilla Add-ons will reject your add-on if you injected remote scripts (meaning code that is not bundled, e.g. originating from e.g. http:) and may also reject your stuff if you track users without prior explicit user consent.
I am trying to load another website from a webpage I am running locally. While it does load, I can not seem to reference anything inside. I keep getting
Blocked a frame with origin "null" from accessing a frame with origin "http://theWebsiteImAccessingWithTheIFrame.com". The frame requesting access has a protocol of "file", the frame being accessed has a protocol of "http". Protocols must match.
I get that this is a security feature, but there must be a way to reference the stuff inside if it is loading it anyway, no?
Any help is greatly appreciated!
Edit:
I have created a map of the office I work in, using SVGs, with everyone's information(office location, their photo, extension, etc). We also just got a bunch of IP Phones that are managed and hosted by LightPath. On the webpage they have, it lets us manage our phones and even make them call others(using javascript but I have no idea how since their code is insanely complex).
My plan was that if a user clicked on someone's office, they could then have a button that would ask them to enter their number and pin to log in(how it works on the lightpath website), it would connect their 2 phones. I intended to use their number and pin to log in for them, and have the call connect that way, by just controlling the forms on lightpath's site, while it was in an iframe. This way, they wouldn't see Lightpath's site's clutter(because I could hide the iframe), and it would just get done. Essentially, it would happen as if they had gone to the website themselves and done it that way, except in a much more approachable format, and with less distractions.
LightPath does offer a "call me" feature which creates a dedicated button for calling a specific person, but it creates a token for them, and only that person has the ability to create it, not to mention I would have to enter each persons' unique token into the site, and run the risk of it failing should their extension get changed, or they leave the company. So I was hoping for something a little more dynamic.
This is a security feature from the browsers.
You can't access iFrames which are not from the same origin.
So the file has to be local.
They have to be on the same server. In chrome you aren't allowed to access any other file in the file:// protocol.
So to access remote files you may want to look into other ways of accessing it.
But either way, you need — at least in Google Chrome — to be on the http:// protocol.
How can I check if a certain link is found in Chrome's browsing history(on the computer that accesses the link) using JavaScript or jQuery? I am interested (if any) in the functions that I have to use. Also how can I get the date and time of the accessed link?
Retrieving the users history from javascript launched from a web page is impossible due to obvious blatant security issues.
Retrieving the users history from javascript running in an extension is possible, but doing so requires elevated permissions that the user has to grant after being warned. In summary you are probably looking for the chrome.history.getVisits() function. You can find more information on how to access the history using chrome.history here and the resulting security warnings given to the user here.
Nonono! That cannot happen. Unless you make a plugin, but I still doubt it.
This might be off topic but you might be interested in google analytics.
this chrome extension allow you to use browser address bar to search keywords, which will automatically search against your browser history and give you suggestion
Chrome webstore - history as bookmark
This is just not possible with Chrome because of security. What you would have to do is use cookies and add to the cookie each page the user is on along with the time visited.
Problem with this it will only track a user on your site not others. Cookies are only suppose to hold small amounts of info not long tracks of what page your user has been on. Also a user can disable cookies...
Another way is maybe doing this serverside and tracking the users IP through your pages and keep a list of what pages your user is visiting.