Solved

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

Posted on 2009-04-07
3
823 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 125 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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
CSS for <center> 14 35
15 puzzle in Javascript/html 2 44
CSS question 4 25
Ways to Manage 2 Development Projects on Same Section 1 19
Today it’s fairly well known that high-performing websites and applications bring in more visitors, higher SEO, and ultimately more sales. By the same token, downtime is disastrous for companies and can lead to major hits on a brand, reputation, an…
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

733 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