Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

NWL

macrumors newbie
Original poster
Jan 20, 2011
5
0
I have this simple asp page that does a post to a different site with the user credentials. This works fine on PC and all browsers but does not work on the mac using Firefox. Basically on the mac all I get is a blank page and it never does the post. Below is the code any help would be great.


Code:
<html>
<head>
<title>Link</title>

<script language=javascript type="text/javascript">

<!--

function getCookieValues( )
{
    var values = [];
    var temp = document.cookie.split( /\;/g );
    for ( var c = 0; c < temp.length; ++c )
    {
        var pair = temp[c].split("=");
        var name = pair[0].replace(/^\s+/,"").replace(/\s$/,"");
        if ( name == "UserIDPW") {
           var val = pair[1].split("&");
           return [ unescape(val[0]),
                    unescape(val[1]) ];
        }
    }
    return null;
}
function getUserIDPWcookie( )
{
var both = getCookieValues( );
    if ( both != null ) 
    {
        var frm = document.LinkForm;
        frm.Account_ID.value = both[0];
        frm.Account_Password.value = both[1];
        frm.submit();
    }
}

//        alert(   "\nusername: " + id[0]
//              + "\npassword: " + pw[1] );
//   }

//-->
</SCRIPT>



<body onLoad="getUserIDPWcookie();" >


<form method="POST" action="http://server1btest.ccc.com/TST/com/check.asp" name="LinkForm" ><br>
<input type='hidden' name='Account_ID' value=""><br>
<input type='hidden' name='Account_Password' value="'pw'"><br> 


</form>
</body>
</html>

I have tried stripping everything done to just the form post but it still does not work.
 
Theres a couple of things, like the person above said you don't have a </head> tag, also the attribute 'language' isn't valid I don't think, plus you wouldn't need to define javascript if you already have type="text/javascript".

Done it for you:
Code:
<html>
<head>
<title>Link</title>

<script type="text/javascript">

<!--

function getCookieValues( )
{
    var values = [];
    var temp = document.cookie.split( /\;/g );
    for ( var c = 0; c < temp.length; ++c )
    {
        var pair = temp[c].split("=");
        var name = pair[0].replace(/^\s+/,"").replace(/\s$/,"");
        if ( name == "UserIDPW") {
           var val = pair[1].split("&");
           return [ unescape(val[0]),
                    unescape(val[1]) ];
        }
    }
    return null;
}
function getUserIDPWcookie( )
{
var both = getCookieValues( );
    if ( both != null ) 
    {
        var frm = document.LinkForm;
        frm.Account_ID.value = both[0];
        frm.Account_Password.value = both[1];
        frm.submit();
    }
}

//        alert(   "\nusername: " + id[0]
//              + "\npassword: " + pw[1] );
//   }

//-->
</script>
</head>


<body onLoad="getUserIDPWcookie();" >


<form method="POST" action="http://server1btest.ccc.com/TST/com/check.asp" name="LinkForm" ><br>
<input type='hidden' name='Account_ID' value=""><br>
<input type='hidden' name='Account_Password' value="'pw'"><br> 


</form>
</body>
</html>
 
Thanks for the corrections and the help. I tried the code above but still get the same issue. Basically Firefox on the mac just says done but never post the information or error out.
 
That's really weird how it's not working on firefox mac but on other browsers it is.. it's probably something really small but I'm useless at Javascript!

Would it be this line?
<input type='hidden' name='Account_Password' value="'pw'"><br>

With the single and double quotations.. try this maybe?

<input type='hidden' name='Account_Password' value="pw"><br>
 
Well, in the function where it will be submitted, you check if the variable both is null. Perhaps it is null. Then the issue would be in the parsing of the cookie in the other function. Use some alert statements or console logs to get a the information. Or you could also use Firebug to debug the code as it is being executed. When I tested locally, both was null.
 
What are you expecting to appear? You have a form with two hidden inputs.

It should post to the page http://server1btest.ccc.com/TST/com/check.asp with the user credentials.

Well, in the function where it will be submitted, you check if the variable both is null. Perhaps it is null. Then the issue would be in the parsing of the cookie in the other function. Use some alert statements or console logs to get a the information. Or you could also use Firebug to debug the code as it is being executed. When I tested locally, both was null.

I believe you are correct. It looks like my cookie is not being passed on to the next firefox window for some reason not sure how to get it to pass the cookie on.
 
Last edited by a moderator:
I believe you are correct. It looks like my cookie is not being passed on to the next firefox window for some reason not sure how to get it to pass the cookie on.

Are you able to provide the code related to setting the cookie leading up to this page? Also check your Firefox preferences on the Privacy tab. There's settings for cookies such as whether to accept 3rd party cookies. I don't think this is a 3rd party cookie though. There's also a setting for how long to keep the cookie.
 
Are you able to provide the code related to setting the cookie leading up to this page? Also check your Firefox preferences on the Privacy tab. There's settings for cookies such as whether to accept 3rd party cookies. I don't think this is a 3rd party cookie though. There's also a setting for how long to keep the cookie.

Here is the code that sets the cookie.

Code:
function setcookie ( cookie_name, cookie_value,lifespan_in_days, valid_domain )
{
    var userid = document.forms[0].username.value;
    var userpw = document.forms[0].password.value;
    document.cookie = "UserIDPW=" + encodeURIComponent( userid ) 
                    + "&" + encodeURIComponent( userpw ) 
                    + "; path=/; domain=.ccc.com" ;
}
 
I see the expiration is being set. It is optional, and should last until the user exits, but it might be a good idea to try and set it explicitly. Remember that it needs to be in GMT format.
PHP:
// Example
var exp = new Date();
exp.setTime(exp.getTime() + 1000*60*60*24*365); // one year
document.cookie = "..." + ';expires=', exp.toGMTString();

Also try using the escape function rather than the encodeURIComponent function because you're using the unescape function in your other code so they don't match up.

Other than that, using Firebug and walking through the code, or using some alert windows at various parts of your code is the only way to really get into it to see where the problem pops up.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.