• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 905
  • Last Modified:

My javascript works in IE and Firefox, but not Chrome.

I have the following javascript code in a form.  It looks at a value of a field in the form and rewrites the links to append the session tab at the end of the url.  This works like it should in IE and Firefox without any problems.  Chrome, however; does not work, nor is it giving me a js error message.  Can anyone point me in the right direction please?  TIA
var sessionID;
function initializepage() {
   if (sessionID==null) {
sessionID=document.forms[0].sessiontab.value
        }
        
    setlinks(sessionID);    
    
    
}
 
function setlinks(v) {
       for (var i = 0; i < document.links.length; i++) {
              document.links[i].search=document.links[i].search + v
             }
}

Open in new window

0
pclark6127
Asked:
pclark6127
  • 2
1 Solution
 
NicksonKohCommented:
Can you the code together with some sample HTML, so that I check out what's wrong?
0
 
pclark6127Author Commented:
Here is the coded page.  Please excuse the commented out code as this is in our test environment.  Thanks!


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>TRDealer Accounts, Etc.</title><LINK REL=stylesheet TYPE="text/css" HREF="/domreg.nsf/stylesheet/$FILE/TRSTYLES.css">
 
<script language="JavaScript" type="text/javascript">
<!-- 
<!-- Begin
redirTime = "0";
redirURL = "http://orders.tuckerrocky.com/CGI-BIN/CGIMENU1";
function redirTimer() { self.setTimeout("self.location.href = redirURL;",redirTime); }
//  End -->
 
 
var sessionID;
function initializepage() {
   if (sessionID==null) {
		sessionID=document.forms[0].sessiontab.value
        }
        
    setlinks(sessionID);    
    
    
 }
 
function setlinks(v) {
       for (var i = 0; i < document.links.length; i++) {
              document.links[i].search=document.links[i].search + v
             }
 }  
 
 
 
 
 
// -->
</script>
 
<script language="JavaScript" type="text/javascript">
<!-- 
document._domino_target = "_self";
function _doClick(v, o, t, h) {
  var form = document._Welcome;
  if (form.onsubmit) {
     var retVal = form.onsubmit();
     if (typeof retVal == "boolean" && retVal == false)
       return false;
  }
  var target = document._domino_target;
  if (o.href != null) {
    if (o.target != null)
       target = o.target;
  } else {
    if (t != null)
      target = t;
  }
  form.target = target;
  form.__Click.value = v;
  if (h != null)
    form.action += h;
  form.submit();
  return false;
}
// -->
</script>
</head>
<body text="#000000" bgcolor="#FFFFFF" onload="initializepage()
">
 
<form method="post" action="/domreg.nsf/welcome?OpenForm&amp;Seq=1&amp;sessiontab=1N" name="_Welcome">
<input type="hidden" name="__Click" value="0"><!-->
<table border="0" cellspacing="0" cellpadding="0">
<tr valign="top"><td width="192">
<input type="button" value="Home" onclick="return _doClick('86256DA30057C59C.d358e5160a1cbd1086256c320059d185/$Body/0.231A', this, null)"></td></tr>
</table>
 
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr valign="top"><td width="100%"><Span Class = Name>USER ID OPTIONS</Span></td></tr>
 
</table>
<br>
<table border="0" cellspacing="0" cellpadding="0">
<tr valign="top"><td width="336"><a href="/domreg.nsf/8f8cc5023a2a89d98525631d006edeb1?OpenForm" title="Change your password for the user you are currently signed on as.">Change Password</a><br><br></td></tr>
 
<tr valign="top"><td width="336">Work with User ID's</td></tr>
 
<tr valign="top"><td width="336">
<table border="0" cellpadding="2" cellspacing="0">
<tr><th></th></tr>
 
<tr valign="top"><td nowrap><img width="16" height="1" src="/icons/ecblank.gif" border="0" alt=""><font size="2"><a href="/domreg.nsf/41d400329ee3207686256bf8004d3fdc/2851a0269dc9cf0886257053006688dd?OpenDocument">kenny</a></font></td></tr>
 
<tr valign="top"><td nowrap><img width="16" height="1" src="/icons/ecblank.gif" border="0" alt=""><font size="2"><a href="/domreg.nsf/41d400329ee3207686256bf8004d3fdc/c50e338b8e38488c862570530066910e?OpenDocument">david</a></font></td></tr>
 
<tr valign="top"><td nowrap><img width="16" height="1" src="/icons/ecblank.gif" border="0" alt=""><font size="2"><a href="/domreg.nsf/41d400329ee3207686256bf8004d3fdc/19be24cc4ae1723686257053006696c7?OpenDocument">clint</a></font></td></tr>
 
<tr valign="top"><td nowrap><img width="16" height="1" src="/icons/ecblank.gif" border="0" alt=""><font size="2"><a href="/domreg.nsf/41d400329ee3207686256bf8004d3fdc/37addfe183bf5af18625705300669a4e?OpenDocument">scotty</a></font></td></tr>
 
<tr valign="top"><td nowrap><img width="16" height="1" src="/icons/ecblank.gif" border="0" alt=""><font size="2"><a href="/domreg.nsf/41d400329ee3207686256bf8004d3fdc/23a9c55c7b4ae42a862570530066ac33?OpenDocument">pablo</a></font></td></tr>
 
<tr valign="top"><td nowrap><img width="16" height="1" src="/icons/ecblank.gif" border="0" alt=""><font size="2"><a href="/domreg.nsf/41d400329ee3207686256bf8004d3fdc/58bad6e340c50eec862570530066d3ce?OpenDocument">gary</a></font></td></tr>
 
<tr valign="top"><td nowrap><img width="16" height="1" src="/icons/ecblank.gif" border="0" alt=""><font size="2"><a href="/domreg.nsf/41d400329ee3207686256bf8004d3fdc/2173d01ecc4d8cd1862570530066e195?OpenDocument">don</a></font></td></tr>
</table>
</td></tr>
 
<tr valign="top"><td width="336"><br><a href="/domreg.nsf/557a6148a8f846d3852563e10000ca95?OpenForm" title="Create a user id for your dealership.">Create a New User ID</a></td></tr>
 
<tr valign="top"><td width="336"><img width="1" height="1" src="/icons/ecblank.gif" border="0" alt=""></td></tr>
</table>
<br><br>
<a href="javascript:alert(document.cookie)" >
javascript:alert(document.cookie)</a><input type="hidden" name="sessiontab" value="&sessiontab=1N"> </form>
</body>
</html>

Open in new window

0
 
NicksonKohCommented:
Hi,

I've checked around some reference and found that the href or link property is read only. IE is an exception because it allows the link to be rewritten.

To minimise the changes to your code, I changed to use window.open to overcome the problem.

Try the code below, it works in IE, Firefox or Chrome.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>ASP Test Page</title>
<LINK REL=stylesheet TYPE="text/css" HREF="/domreg.nsf/stylesheet/$FILE/TRSTYLES.css">
<script language="JavaScript" type="text/javascript">
<!--
<!-- Begin
redirTime = "0";
redirURL = "http://orders.tuckerrocky.com/CGI-BIN/CGIMENU1";
function redirTimer() {
  self.setTimeout("self.location.href = redirURL;", redirTime);
 
}
//  End -->
 
 
var sessionID;
function initializepage() {
  if (typeof sessionID == "undefined")   {
    sessionID = document.forms[0].sessiontab.value
  }
  // setlinks(sessionID);
}
 
/*
function setlinks(v) {
for (var i = 0; i < document.links.length; i ++ ) {
var tmp = document.links[i].search + v;
document.links[i].search = tmp;
}
}
 */
 
function OpenURL(lnk)  {
  window.open(lnk + sessionID, "_self");
  return false;
}
// -->
</script>
<script language="JavaScript" type="text/javascript">
<!--
document._domino_target = "_self";
function _doClick(v, o, t, h) {
  var form = document._Welcome;
  if (form.onsubmit) {
    var retVal = form.onsubmit();
    if (typeof retVal == "boolean" && retVal == false)
    return false;
  }
  var target = document._domino_target;
  if (o.href != null) {
    if (o.target != null)
    target = o.target;
  }
  else {
    if (t != null)
    target = t;
  }
  form.target = target;
  form.__Click.value = v;
  if (h != null)
  form.action += h;
  form.submit();
  return false;
}
// -->
</script>
</head>
<body text="#000000" bgcolor="#FFFFFF" onLoad="initializepage()">
<form method="post" action="/domreg.nsf/welcome?OpenForm&amp;Seq=1&amp;sessiontab=1N" name="_Welcome">
  <input type="hidden" name="__Click" value="0">
  <table border="0" cellspacing="0" cellpadding="0">
    <tr valign="top">
      <td width="192"><input type="button" value="Home" onClick="return _doClick('86256DA30057C59C.d358e5160a1cbd1086256c320059d185/$Body/0.231A', this, null)"></td>
    </tr>
  </table>
  <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr valign="top">
      <td width="100%"><Span Class = Name>USER ID OPTIONS</Span></td>
    </tr>
  </table>
  <br>
  <table border="0" cellspacing="0" cellpadding="0">
    <tr valign="top">
      <td width="336"><a href="/domreg.nsf/8f8cc5023a2a89d98525631d006edeb1?OpenForm" title="Change your password for the user you are currently signed on as.">Change Password</a><br>
        <br></td>
    </tr>
    <tr valign="top">
      <td width="336">Work with User ID's</td>
    </tr>
    <tr valign="top">
      <td width="336"><table border="0" cellpadding="2" cellspacing="0">
          <tr>
            <th></th>
          </tr>
          <tr valign="top">
            <td nowrap><img width="16" height="1" src="/icons/ecblank.gif" border="0" alt=""><font size="2"><a href="/domreg.nsf/41d400329ee3207686256bf8004d3fdc/2851a0269dc9cf0886257053006688dd?OpenDocument" onclick="return OpenURL(this)">kenny</a></font></td>
          </tr>
          <tr valign="top">
            <td nowrap><img width="16" height="1" src="/icons/ecblank.gif" border="0" alt=""><font size="2"><a href="/domreg.nsf/41d400329ee3207686256bf8004d3fdc/c50e338b8e38488c862570530066910e?OpenDocument" onclick="return OpenURL(this)">david</a></font></td>
          </tr>
          <tr valign="top">
            <td nowrap><img width="16" height="1" src="/icons/ecblank.gif" border="0" alt=""><font size="2"><a href="/domreg.nsf/41d400329ee3207686256bf8004d3fdc/19be24cc4ae1723686257053006696c7?OpenDocument" onclick="return OpenURL(this)">clint</a></font></td>
          </tr>
          <tr valign="top">
            <td nowrap><img width="16" height="1" src="/icons/ecblank.gif" border="0" alt=""><font size="2"><a href="/domreg.nsf/41d400329ee3207686256bf8004d3fdc/37addfe183bf5af18625705300669a4e?OpenDocument" onclick="return OpenURL(this)">scotty</a></font></td>
          </tr>
          <tr valign="top">
            <td nowrap><img width="16" height="1" src="/icons/ecblank.gif" border="0" alt=""><font size="2"><a href="/domreg.nsf/41d400329ee3207686256bf8004d3fdc/23a9c55c7b4ae42a862570530066ac33?OpenDocument" onclick="return OpenURL(this)">pablo</a></font></td>
          </tr>
          <tr valign="top">
            <td nowrap><img width="16" height="1" src="/icons/ecblank.gif" border="0" alt=""><font size="2"><a href="/domreg.nsf/41d400329ee3207686256bf8004d3fdc/58bad6e340c50eec862570530066d3ce?OpenDocument" onclick="return OpenURL(this)">gary</a></font></td>
          </tr>
          <tr valign="top">
            <td nowrap><img width="16" height="1" src="/icons/ecblank.gif" border="0" alt=""><font size="2"><a href="/domreg.nsf/41d400329ee3207686256bf8004d3fdc/2173d01ecc4d8cd1862570530066e195?OpenDocument" onclick="return OpenURL(this)">don</a></font></td>
          </tr>
        </table></td>
    </tr>
    <tr valign="top">
      <td width="336"><br>
        <a href="/domreg.nsf/557a6148a8f846d3852563e10000ca95?OpenForm" title="Create a user id for your dealership.">Create a New User ID</a></td>
    </tr>
    <tr valign="top">
      <td width="336"><img width="1" height="1" src="/icons/ecblank.gif" border="0" alt=""></td>
    </tr>
  </table>
  <br>
  <br>
  <a href="javascript:alert(document.cookie)" > javascript:alert(document.cookie)</a>
  <input type="hidden" name="sessiontab" value="&sessiontab=1N">
</form>
</body>
</html>

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now