Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Change existing link's href - weird IE bug.

Reply
Thread Tools

Change existing link's href - weird IE bug.

 
 
automatyk
Guest
Posts: n/a
 
      01-16-2008
I need to change an href on an existing link in my document depending
on some user input.
I was able to get this to work in Firefox, but the behavior in IE is
troubling. The new link works in both browsers, however, IE rewrites
the entire link text! This is my code:

<script type="text/javascript">
function getContractNum() {
var cNum = document.forms[0].contractNum.value;
var cNum1 = document.forms[0].contractNum1.value;
var cComplete;
if (cNum != '') {
subjectline = cNum;
} else if (cNum1 != '') {
subjectline = cNum1;
} else {
subjectline = 'x';
}

var newlink = '(E-Mail Removed)?subject=Rep Payee%20:%20' +
subjectline;
var target = document.getElementById("dynamicsubject");
target.setAttribute('href', newlink);
}
</script>

My HTML contains a form with a couple of inputs and a link.

<a id="dynamicsubject" href="mailto://(E-Mail Removed)">Click here to
send email.</a>

Firefox behaves as you'd expect... the href is changed and the link
text is the same.
Internet Explorer however displays:
(E-Mail Removed)?subject=Rep Payee%20:%20x

The link works in both cases! Can anyone help me figure this out?
It's been driving me crazy all day!

Thanks.
 
Reply With Quote
 
 
 
 
Doug Gunnoe
Guest
Posts: n/a
 
      01-16-2008
On Jan 16, 3:26*pm, automatyk <(E-Mail Removed)> wrote:
> I need to change an href on an existing link in my document depending
> on some user input.
> I was able to get this to work in Firefox, but the behavior in IE is
> troubling. *The new link works in both browsers, however, IE rewrites
> the entire link text! *This is my code:
>
> <script type="text/javascript">
> * * * * function getContractNum() {
> * * * * * * * * var cNum = document.forms[0].contractNum..value;
> * * * * * * * * var cNum1 = document.forms[0].contractNum1.value;
> * * * * * * * * var cComplete;
> * * * * * * * * if (cNum != '') {
> * * * * * * * * * * * * subjectline = cNum;
> * * * * * * * * } else if (cNum1 != '') {
> * * * * * * * * * * * * subjectline = cNum1;
> * * * * * * * * } else {
> * * * * * * * * * * * * subjectline = 'x';
> * * * * * * * * }
>
> * * * * * * * * var newlink = '(E-Mail Removed)?subject=Rep Payee%20:%20' +
> subjectline;
> * * * * * * * * var target = document.getElementById("dynamicsubject");
> * * * * * * * * target.setAttribute('href', newlink);
> * * * * }
> </script>
>
> My HTML contains a form with a couple of inputs and a link.
>
> <a id="dynamicsubject" href="mailto:/(E-Mail Removed)">Click here to
> send email.</a>
>
> Firefox behaves as you'd expect... the href is changed and the link
> text is the same.
> Internet Explorer however displays:
> (E-Mail Removed)?subject=Rep Payee%20:%20x
>
> The link works in both cases! *Can anyone help me figure this out?
> It's been driving me crazy all day!
>
> Thanks.


Have you tried to do target.href = newLink instead of using
setAttribute?
 
Reply With Quote
 
 
 
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      01-16-2008
automatyk wrote:
> I need to change an href on an existing link in my document depending
> on some user input.
> I was able to get this to work in Firefox, but the behavior in IE is
> troubling. The new link works in both browsers, however, IE rewrites
> the entire link text! [...]
> My HTML contains a form with a couple of inputs and a link.
>
> <a id="dynamicsubject" href="mailto://(E-Mail Removed)">Click here to
> send email.</a>
>
> Firefox behaves as you'd expect... the href is changed and the link
> text is the same.
> Internet Explorer however displays:
> (E-Mail Removed)?subject=Rep Payee%20:%20x


WFM in

- Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1;
{3E1C4754-F096-BBFE-CD76-3B2E8F19E202}; .NET CLR 2.0.50727)

- Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;
{3E1C4754-F096-BBFE-CD76-3B2E8F19E202}; .NET CLR 2.0.50727)
(standalone)

- Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.1;
{3E1C4754-F096-BBFE-CD76-3B2E8F19E202}; .NET CLR 2.0.50727)
(standalone)

Please post a public URL of your test case.


PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f806at$ail$1$(E-Mail Removed)>
 
Reply With Quote
 
automatyk
Guest
Posts: n/a
 
      01-17-2008
Thanks for the input everyone!

Unfortunately, my site is on a corporate intranet so I cannot post a
link. (FTP is locked down as well )
I've tried the "target.href = newLink" method - it behaves the same.

I'll rename the "target" variable to see if that's the issue. If that
fails, however, I'll assume that the corporate branded IE7 is the
culprit.

I'll post a solution if I solve the problem.


On Jan 16, 6:52 pm, Thomas 'PointedEars' Lahn <(E-Mail Removed)>
wrote:
> automatyk wrote:
> > I need to change an href on an existing link in my document depending
> > on some user input.
> > I was able to get this to work in Firefox, but the behavior in IE is
> > troubling. The new link works in both browsers, however, IE rewrites
> > the entire link text! [...]
> > My HTML contains a form with a couple of inputs and a link.

>
> > <a id="dynamicsubject" href="mailto:/(E-Mail Removed)">Click here to
> > send email.</a>

>
> > Firefox behaves as you'd expect... the href is changed and the link
> > text is the same.
> > Internet Explorer however displays:
> > (E-Mail Removed)?subject=Rep Payee%20:%20x

>
> WFM in
>
> - Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1;
> {3E1C4754-F096-BBFE-CD76-3B2E8F19E202}; .NET CLR 2.0.50727)
>
> - Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;
> {3E1C4754-F096-BBFE-CD76-3B2E8F19E202}; .NET CLR 2.0.50727)
> (standalone)
>
> - Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.1;
> {3E1C4754-F096-BBFE-CD76-3B2E8F19E202}; .NET CLR 2.0.50727)
> (standalone)
>
> Please post a public URL of your test case.
>
> PointedEars
> --
> Prototype.js was written by people who don't know javascript for people
> who don't know javascript. People who don't know javascript are not
> the best source of advice on designing systems that use javascript.
> -- Richard Cornford, cljs, <f806at$ail$1$(E-Mail Removed)>


 
Reply With Quote
 
Dr J R Stockton
Guest
Posts: n/a
 
      01-17-2008
In comp.lang.javascript message <(E-Mail Removed)>,
Wed, 16 Jan 2008 17:16:26, Randy Webb <(E-Mail Removed)> posted:
>
>Why do people have such a hard time posting code indented with spaces
>and not tabs?
>


Because the matter is not mentioned in section 2,3 if the FAQ which you
supposedly maintain?

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/&c., FAQqy topics & links;
<URL:http://www.merlyn.demon.co.uk/clpb-faq.txt> RAH Prins : c.l.p.b mFAQ;
<URL:ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip> Timo Salmi's Turbo Pascal FAQ.
 
Reply With Quote
 
The Natural Philosopher
Guest
Posts: n/a
 
      01-17-2008
automatyk wrote:
> Thanks for the input everyone!
>
> Unfortunately, my site is on a corporate intranet so I cannot post a
> link. (FTP is locked down as well )
> I've tried the "target.href = newLink" method - it behaves the same.
>
> I'll rename the "target" variable to see if that's the issue. If that
> fails, however, I'll assume that the corporate branded IE7 is the
> culprit.
>
> I'll post a solution if I solve the problem.
>


Why not sidestep it, make the URL a dummy (text only) and use onclick()
to generate a window.open thing?

Either you are trying to avoid javascript like the plague, or you are
using it because you must. In which case use it. In the most browser
independent way.



>
> On Jan 16, 6:52 pm, Thomas 'PointedEars' Lahn <(E-Mail Removed)>
> wrote:
>> automatyk wrote:
>>> I need to change an href on an existing link in my document depending
>>> on some user input.
>>> I was able to get this to work in Firefox, but the behavior in IE is
>>> troubling. The new link works in both browsers, however, IE rewrites
>>> the entire link text! [...]
>>> My HTML contains a form with a couple of inputs and a link.
>>> <a id="dynamicsubject" href="mailto:/(E-Mail Removed)">Click here to
>>> send email.</a>
>>> Firefox behaves as you'd expect... the href is changed and the link
>>> text is the same.
>>> Internet Explorer however displays:
>>> (E-Mail Removed)?subject=Rep Payee%20:%20x

>> WFM in
>>
>> - Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1;
>> {3E1C4754-F096-BBFE-CD76-3B2E8F19E202}; .NET CLR 2.0.50727)
>>
>> - Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;
>> {3E1C4754-F096-BBFE-CD76-3B2E8F19E202}; .NET CLR 2.0.50727)
>> (standalone)
>>
>> - Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.1;
>> {3E1C4754-F096-BBFE-CD76-3B2E8F19E202}; .NET CLR 2.0.50727)
>> (standalone)
>>
>> Please post a public URL of your test case.
>>
>> PointedEars
>> --
>> Prototype.js was written by people who don't know javascript for people
>> who don't know javascript. People who don't know javascript are not
>> the best source of advice on designing systems that use javascript.
>> -- Richard Cornford, cljs, <f806at$ail$1$(E-Mail Removed)>

>

 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      01-17-2008
automatyk wrote:
> I need to change an href on an existing link in my document depending on
> some user input. I was able to get this to work in Firefox, but the
> behavior in IE is troubling. The new link works in both browsers,
> however, IE rewrites the entire link text! This is my code:


I see two irregularities in your code:

> [...]
> var newlink = '(E-Mail Removed)?subject=Rep Payee%20:%20' +
> subjectline;


There is a space character in the mailto: URI that was not escaped with
`%20'. URIs must not contain unescaped spaces.

> [...]
> <a id="dynamicsubject" href="mailto://(E-Mail Removed)">Click here to
> send email.</a>


mailto: is a URI, not a URL. Remove the `//'.

That said, you should not use `mailto:' URIs as it requires a local e-mail
client, and a user agent that has it set as handler for those URIs. Set a
link to a form-mailer instead.


HTH

PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
 
Reply With Quote
 
automatyk
Guest
Posts: n/a
 
      01-17-2008
Thomas,

I am trapped in corporate intranet land where I don't have the luxury
of access to code things properly. Everything is an ordeal. I can
have javascript! That's all. Thanks for catching the space issue.

Company wide, we've got IE7 and Outlook. That's all we're officially
supposed to support. I'm still puzzled by the setAttribute issue on
IE7. FF works just fine.

-G


On Jan 17, 2:04 pm, Thomas 'PointedEars' Lahn <(E-Mail Removed)>
wrote:
> automatyk wrote:
> > I need to change an href on an existing link in my document depending on
> > some user input. I was able to get this to work in Firefox, but the
> > behavior in IE is troubling. The new link works in both browsers,
> > however, IE rewrites the entire link text! This is my code:

>
> I see two irregularities in your code:
>
> > [...]
> > var newlink = '(E-Mail Removed)?subject=Rep Payee%20:%20' +
> > subjectline;

>
> There is a space character in the mailto: URI that was not escaped with
> `%20'. URIs must not contain unescaped spaces.
>
> > [...]
> > <a id="dynamicsubject" href="mailto:/(E-Mail Removed)">Click here to
> > send email.</a>

>
> mailto: is a URI, not a URL. Remove the `//'.
>
> That said, you should not use `mailto:' URIs as it requires a local e-mail
> client, and a user agent that has it set as handler for those URIs. Set a
> link to a form-mailer instead.
>
> HTH
>
> PointedEars
> --
> var bugRiddenCrashPronePieceOfJunk = (
> navigator.userAgent.indexOf('MSIE 5') != -1
> && navigator.userAgent.indexOf('Mac') != -1
> ) // Plone, register_function.js:16


 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      01-17-2008
automatyk wrote:
> I am trapped in corporate intranet land where I don't have the luxury
> of access to code things properly. Everything is an ordeal. I can
> have javascript! That's all.


Please don't play stupid, you are insulting the intelligence of your readers.

Since you can post here via Google Groups, it is possible for you
to get access to some freely available reference material like
<http://rfc-editor.org/rfc/rfc3986.txt> and
<http://rfc-editor.org/rfc/rfc2368.txt>

And although it certainly helps, you don't *need* an IDE to write proper
code, only Brain 1.0.

> Thanks for catching the space issue.


You're welcome. Don't forget to fix the `//' issue, and thanks for proper
quoting next time:

> [...]
> [full quote]


http://www.jibbering.com/faq/faq_not...s.html#ps1Post


PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f806at$ail$1$(E-Mail Removed)>
 
Reply With Quote
 
automatyk
Guest
Posts: n/a
 
      01-17-2008

> Please don't play stupid, you are insulting the intelligence of your readers.


A little harsh maybe? A couple tiny mistakes do not warrant such a
statement.

My "trapped in corporate intranet land" comment isn't an excuse to
write bad code. I'm not implying that. I'm simply stating that due
to the fact that I'm locked out of any server side language and locked
out of many resources most programmers take for granted, I am forced
to come up with bastardized solutions from time to time. Forgive me.

Good day.


On Jan 17, 3:06 pm, Thomas 'PointedEars' Lahn <(E-Mail Removed)>
wrote:
> automatyk wrote:
> > I am trapped in corporate intranet land where I don't have the luxury
> > of access to code things properly. Everything is an ordeal. I can
> > have javascript! That's all.

>
> Please don't play stupid, you are insulting the intelligence of your readers.
>
> Since you can post here via Google Groups, it is possible for you
> to get access to some freely available reference material like
> <http://rfc-editor.org/rfc/rfc3986.txt> and
> <http://rfc-editor.org/rfc/rfc2368.txt>
>
> And although it certainly helps, you don't *need* an IDE to write proper
> code, only Brain 1.0.
>
> > Thanks for catching the space issue.

>
> You're welcome. Don't forget to fix the `//' issue, and thanks for proper
> quoting next time:
>
> > [...]
> > [full quote]

>
> http://www.jibbering.com/faq/faq_not...s.html#ps1Post
>
> PointedEars
> --
> Prototype.js was written by people who don't know javascript for people
> who don't know javascript. People who don't know javascript are not
> the best source of advice on designing systems that use javascript.
> -- Richard Cornford, cljs, <f806at$ail$1$(E-Mail Removed)>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
BASE HREF and A HREF="#" onclick="..." Vincent van Beveren Javascript 2 07-06-2006 08:33 AM
href="javascript:func()" vs href="#" onclick="javascript:func()" CRON HTML 24 06-20-2006 08:05 PM
onClick method question (this.href and document.location.href) yogesh.bhardwaj@gmail.com Javascript 2 02-03-2005 02:38 PM
difference between location.href and window.location.href? saiho.yuen Javascript 3 09-14-2004 06:51 PM
Problem: Setting MSIE iframe innerHTML change relative href/src to absolute href/src Soren Vejrum Javascript 4 07-05-2003 01:47 PM



Advertisments