开发者

Detect Internet using JavaScript and perform action

Hopefully someone can help me here. I use a login page everyday given by my ISP to login and start internet on my machine. In between the connection goes off a couple of times and I am redirecte开发者_JAVA百科d to the login page. On clicking the Login button, the internet starts again.

My question. Can I automatically detect if the internet is off and use a script that auto logs me in.

THe Login button on the redirected page looks like this

<input type="submit" name="Submit" id="btnSubmit" value="Login" onclick="return checking();" />


The real problem may be in a DSL modem and/or setup. For example, I've seen this a lot with people using 2Wire brand modems.

But the general task is a common one.   The following is a generic Greasemonkey script that will work -- but you will have to tweak it slightly because enough of the login page was not provided.

Ideally, save the entire login page, strip out any IP addresses or passwords and then paste it here or at Pastebin.com. Then we can give a more exact solution.

Script:

// ==UserScript==
// @name            Generic Auto Relogin
// @namespace       GenericLocal
// @description     Just removes a login annoyance.  WARNING:  This compromises security!
// @include         *
// @require         http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js
// ==/UserScript==


$(document).ready(Greasemonkey_main);


/*--- WARNING!  Username and password!!!
*/
var sGbl_Username       = 'For demonstration purposes only!';
var sGbl_Password       = 'Hopefully you know that this is a bad idea';


function Greasemonkey_main ()
{
    //--- Is this a login screen? ---
    var zLoginForm      = $("input#btnSubmit");
    if (zLoginForm  &&  zLoginForm.length)
    {
        //--- Set username and password. ---
        $("input#username").attr ('value', sGbl_Username);
        $("input#password").attr ('value', sGbl_Password);

        //--- Submit the login form.
        $("input#btnSubmit")[0].click (); //-- Click submit button.
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜