Script to automatically submit form in any browser - javascript

Note: I could not think words for this question to search in Google. That's why asking my question. Please bear with me.
I have internet subscription of xyz company and it's login based connection. But what happens is that sometimes login screen reappears and is asking for password. I have already stored user name and password in web page but I have to click on login button to relogin again.
Can I have any script written for this login page that whenever internet connection goes and asks for relogin again, script automatically submit form and get connected with internet?

You're looking for content scripts. There is no cross-browser way to inject code into a web page, but each major browser has a well documented way to do it:
Firefox
Chrome
Internet Explorer
Technically you could also write a script that sniffs HTTP requests using a tool like Wireshark and posts form data whenever it detects the page is displayed, but that doesn't seem like a great solution.

Related

Making an iframe inherit cookies from the parent in Safari

My web app extends a Google Form's functionality by loading it as an iframe, and doing other stuff outside the iframe. If the Google Form requires authentication, Google makes a "Sign In" box appears within the iframe. When a user clicks on the button, a new tab opens, and the user is re-directed to the form in the new tab.
If a user navigates away from my web app, the extra functionality will obviously not work. So, what I am looking for is: to have an authenticated Google Form load as an iframe within my web app.
I can make the user first sign in via Google Sign-In (OAuth) on my web app and then load the iframe. On Chrome and Firefox, the iframe automatically starts with a logged-in session. This is great! But, this solution doesn't work on Safari. Is this related to Safari blocking third-party cookies?
If I want this functionality to work within Safari (and other such browsers), how would I go about doing it? Will I have to use the Storage Access API? If yes, can you broadly tell me how to do it?
For now, I could just ask users to download Firefox/Chrome if they want to use my web app. Most of my users are Chrome users anyway. But, is implementing these privacy measures a part of other browsers' roadmap too? If yes, I may as well try and build a solution that will work in a year or two.
I expect so.
This needs to happen in the iFrame, so Google rather than you need to implement it.
Yes, but not until 2022, so I would hope Google forms will support this by then.

Javascript - Show message when "No connectivity detected”

Please note that this question is in consequence of another question: "Codename One - ToastBar when “No connectivity detected"
What is a correct approach (in Javascript or JQuery) to deal with Internet connection unavailability (that is common on mobile devices)?
Every time that there is a networking error, I would like to show a message to the user (like this one: https://i.stack.imgur.com/Ll6jD.png) and pause the Internet activity of the web page, in a way that no errors are generated (and the messages written by the user, for example in an html form, are not lost). The Internet activity should be (automatically) restored when the connection will be available again.
This should be a convenient way to allow people to interact with a web site (from mobile devices) without the risk of losing their posts or comments and without receive errors when they click a link.
This functionality should be as much as possible independent from the specific web site. What is a correct way to implement it?
use jquery plugin like this :
Offline.js

Is it at all possible to determine whether the running browser is the default browser in JavaScript?

It would be very useful, in my application, to know whether the current browser is the default browser.
Is is possible, using JavaScript, to know whether the browser my page is opened in is the default browser (i.e. the browser that would open if I were to click on a link in another app. like, for example, an email reader)?
Update
To answer E. Sundin and other possible readers, there is the main reason why I would like to know whether the current browser is the default browser:
When a user registers on one of my websites, I register the User-Agent as a token that should not change between the time the user registers and the time the user clicks on the email verification link. Unfortunately, when users click on the link, it opens in the default browser.
If I knew, I could do several things:
Not put a link in the email, just ask the user to copy/paste the token to his still open browser
Warn the user as he is registering that it won't work if he just follows the link (if I know that this browser is not the default.)
Eventually ignore that test (that could be an admin. setup, in most cases website owners do not care that much... so not having such a test would be similar to nearly all other websites. Reduced security, but since the majority does that anyway...)
Of course, it happens that people register on their smart phone, receive their email on their desktop and follow the link there. That would also not work well with such a test...
No, there is no Javascript API for this.
Keep in mind that not all operating systems even have the concept of a "default browser".

Javascript Confirm method Kills my session data on Safari 5.0.2

There is something seriously wrong here. I am about a 100% sure the confirm method is causing serious issues with sessions on Safari. The confirm prompt basically asks the user to make sure he/she wants to go through with an action before pulling off a Jquery POST. This works fine on every other browser, but on Safari the users session data gets deleted and they get logged out upon refreshing the page. I removed the method and everything is back to normal. Has anyone experienced this before? Very strange... shakes fist at apple
Edit: I tried using Jqueries Dialog widget and I am experiencing the same issues. What do you think is going on?
Edit2: For those who are curious, the alert doesn't wipe out the session data, it just brings the control back to the client end therefore the browser isn't really in touch with its server side. This comment explains it best:
You have to be mindful of where your code is running when you are
using ASP.NET. In your example, since you are using the Session
object, you are running on the server. Your web server has no way of
popping up an alert dialog on the user's machine. Instead, it has to
write JavaScript code to the client, which can then execute this code
and give the user an alert. So, you need to change your approach. If
you need the alert, you will need to feed the information to the
client, and have the entire check take place there, in which case you
lose access to your session variable (stored on the server), so the
only comparison you will be able to do is based on something on that
form or else something that you write out to the client machine.
Reference: http://www.velocityreviews.com/forums/t65880-javascript-alert-function.html
It's ridiculous to see that Safari does not automatically handle this situation like it's counterparts.
Edit3: More proof! A quick google search revealed lots of people on Safari have complaints about getting signed out of facebook randomly. Facebook also has pop up balloon warnings that notify you about important instances such as walking away from a half written message. I get logged out every time that balloon warns me! It's like a tough bouncer for Safari. What is going on here?
Okay, here's the solution, if you are running Safari 5.0.5 UPDATE NOW! 5.0.5 is junk. Call this a coincidence but for me this has reenforced the age long cliche about Apples inability to develop good software.

Can I Create Chrome Application Shortcuts Programmatically from a Web Page?

I've thought about using Chrome and HTML5 local storage to create a useful app and sell it. The problem I think I would have, however, is the delivery mechanism to get this installed on one's computer. Let's say the app was wikipedia.com (although it isn't). Manually one can go there with Chrome, then choose the wrench icon, Tools, Create Application Shortcuts, and make a desktop and application menu icon for the app.
Okay, fine, but is there a way I can compose a web page link or form button such that it does this for me? In other words, one clicks a button or link and it shows the Create Application Shortcuts form. I am hoping that there's this little-known way on Google Chrome to use either HTML or Javascript to trigger showing that form.
As for those who don't have Chrome, I can detect that and give them a button they click that emails them. In the email, it will give them instructions for installing Chrome and then another link so that they can visit this page in Chrome in order to get the button that shows the Create Application Shortcuts form.
For now, until a better answer can be provided, this is sort of the technique for deploying a desktop app with Chrome, the manual way, and without having to register in the Chrome Store:
After the user purchases a product, email them the serial number for registering their product and a web URL to install this new product.
The web URL is the actual URL of the web app. However, it doesn't display its normal content by default. Instead, the web app is in "installer mode". It does this by looking at a 200 year persistent, encrypted, registration cookie that may not already be installed. (Note if they delete cookies, there's no harm done -- it just asks them to re-register again.)
The first thing the web app does in Installer Mode is detect user agent. If it finds this is not Chrome, it gives them a link to install Chrome and tells them to follow the instruction email again that they have already been sent, but using Chrome to do this. (You might also want to provide a form to resend them the instructions and serial number again.)
The user either installs Chrome and returns back to this page again, or is already a Chrome user. The Installer Mode then shows a message that reads, please press the ALT-F key in Chrome, or press the Wrench icon in your toolbar, and choose Tools > Create Application Shortcuts, check the two checkboxes, click OK, and then click the "Task Performed" button below.
The user follows the instructions and creates their desktop/application shortcut and then clicks "Task Performed".
The user then sees a registration form where they are to type in their serial number they were emailed. The user enters this in and clicks the Register button.
The server validates the registration and then stores a persistent, 200 year encrypted cookie that basically says, "This guy is registered." This keeps the web app from running in Installer Mode.
The Installer Mode is still active, however, and shows them the final prompt: "You may close your browser and run the icon for the new app from your desktop or application shortcut that you created. The icon is named '{insert name here}'."
They close their browser and doubleclick the icon. The application loads, the registration cookie is read, and the web app no longer runs in Installer Mode -- it shows the application content like it normally would. Besides the fact that this is not a 100% truly automated install, the only drawback is that, since the main page is not a local file (cached), the web app can't really work offline completely. Sure, it can use HTML5 offline storage, but doubleclicking the desktop shortcut will always connect to your web app site.

Categories

Resources