?
Solved

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

Posted on 2009-04-07
3
Medium Priority
?
867 Views
Last Modified: 2012-08-14
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
Comment
Question by:pclark6127
  • 2
3 Comments
 
LVL 17

Expert Comment

by:NicksonKoh
ID: 24093286
Can you the code together with some sample HTML, so that I check out what's wrong?
0
 
LVL 1

Author Comment

by:pclark6127
ID: 24097500
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
 
LVL 17

Accepted Solution

by:
NicksonKoh earned 500 total points
ID: 24104189
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to implement server side field validation and display customized error messages to the client.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question