Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > string to href? [rookie]

Reply
Thread Tools

string to href? [rookie]

 
 
cerr
Guest
Posts: n/a
 
      09-02-2011
Hi There,

I got a link as follows:
<a href="xyz.com">xyz</a>
and a javascript function gethtml('es') that returns the url string.
Now how do i get the url string into the html link in
<a href="MyString">?

Thank you!
 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      09-02-2011
cerr wrote:

> I got a link as follows:
> <a href="xyz.com">xyz</a>


Where is that link, is it part of the HTML document inside the browser
that you want to manipulate by script?

> and a javascript function gethtml('es') that returns the url string.
> Now how do i get the url string into the html link in
> <a href="MyString">?


Well if you have the link element object you can simply set
link.href = gethtml('es');
You can find all links in the
document.links
collection so if you want to find a particular link element based on the
existing href attribute value you could loop through document.links.



--

Martin Honnen --- MVP Data Platform Development
http://msmvps.com/blogs/martin_honnen/
 
Reply With Quote
 
 
 
 
Tim Streater
Guest
Posts: n/a
 
      09-02-2011
In article
<(E-Mail Removed)>,
cerr <(E-Mail Removed)> wrote:

> Hi There,
>
> I got a link as follows:
> <a href="xyz.com">xyz</a>
> and a javascript function gethtml('es') that returns the url string.
> Now how do i get the url string into the html link in
> <a href="MyString">?


What's 'es' got to do with anything? And I would post from google
groups, I expect most people are filtering that out at present.

--
Tim

"That excessive bail ought not to be required, nor excessive fines imposed,
nor cruel and unusual punishments inflicted" -- Bill of Rights 1689
 
Reply With Quote
 
cerr
Guest
Posts: n/a
 
      09-02-2011
On Sep 2, 10:06*am, Martin Honnen <(E-Mail Removed)> wrote:
> cerr wrote:
> > I got a link as follows:
> > <a href="xyz.com">xyz</a>

>
> Where is that link, is it part of the HTML document inside the browser
> that you want to manipulate by script?
>
> > and a javascript function gethtml('es') that returns the url string.
> > Now how do i get the url string into the html link in
> > <a href="MyString">?

>
> Well if you have the link element object you can simply set
> * *link.href = gethtml('es');
> You can find all links in the
> * *document.links
> collection so if you want to find a particular link element based on the
> existing href attribute value you could loop through document.links.
>
> --
>
> * * * * Martin Honnen --- MVP Data Platform Development
> * * * *http://msmvps.com/blogs/martin_honnen/


it is a regular link in the html document. What i want to do is:
I have a complete page in english and i'll add multiple languages. The
design has one design template that will always be the same for all
the pages. on top i got buttons linking to different languages, my
function reads out the address bar content, manipulates the url (by
adding the language to this particular page) so that the link would
link to this page in a different langfuage... does that make sense?
So I just want to do document.write(gethtml('es')); for example.

Thanks,
Ron
 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      09-02-2011
cerr wrote:

> it is a regular link in the html document. What i want to do is:
> I have a complete page in english and i'll add multiple languages. The
> design has one design template that will always be the same for all
> the pages. on top i got buttons linking to different languages, my
> function reads out the address bar content, manipulates the url (by
> adding the language to this particular page) so that the link would
> link to this page in a different langfuage... does that make sense?
> So I just want to do document.write(gethtml('es')); for example.


Does the function gethtml already exist? Then post its code so that we
can see what it does.
If you want to use document.write then do that but it does not help to
manipulate existing links, you can only write new ones or additional
ones that way.

However relying on client-side scripting to get links to work properly
does not seem like a good idea.



--

Martin Honnen --- MVP Data Platform Development
http://msmvps.com/blogs/martin_honnen/
 
Reply With Quote
 
cerr
Guest
Posts: n/a
 
      09-02-2011
On Sep 2, 10:36*am, Martin Honnen <(E-Mail Removed)> wrote:
> cerr wrote:
> > it is a regular link in the html document. What i want to do is:
> > I have a complete page in english and i'll add multiple languages. The
> > design has one design template that will always be the same for all
> > the pages. on top i got buttons linking to different languages, my
> > function reads out the address bar content, manipulates the url (by
> > adding the language to this particular page) so that the link would
> > link to this page in a different langfuage... does that make sense?
> > So I just want to do document.write(gethtml('es')); for example.

>
> Does the function gethtml already exist? Then post its code so that we
> can see what it does.


function gethtml(lang){
var url = window.location.href;
url = url.replace("http://quaaoutlodge.com/","http://quaaoutlodge.com/
lang/"+lang+"/");
return url;
}

> If you want to use document.write then do that but it does not help to
> manipulate existing links, you can only write new ones or additional
> ones that way.


I don't want to manipulate it but just to write it.

> However relying on client-side scripting to get links to work properly
> does not seem like a good idea.


True too but i still would like to try it this way...

Thanks for your help!
 
Reply With Quote
 
cerr
Guest
Posts: n/a
 
      09-02-2011
On Sep 2, 10:11*am, Tim Streater <(E-Mail Removed)> wrote:
> In article
> <(E-Mail Removed)>,
>
> *cerr <(E-Mail Removed)> wrote:
> > Hi There,

>
> > I got a link as follows:
> > <a href="xyz.com">xyz</a>
> > and a javascript function gethtml('es') that returns the url string.
> > Now how do i get the url string into the html link in
> > <a href="MyString">?

>
> What's 'es' got to do with anything? And I would post from google
> groups, I expect most people are filtering that out at present.


I do post from google groups and why would people filter it out
anyways?

'es' is just the language it should switch to - spanish in this
example:

function gethtml(lang){
var url = window.location.href;
url = url.replace("http://quaaoutlodge.com/","http://quaaoutlodge.com/
lang/"+lang+"/");
return url;
}

 
Reply With Quote
 
Tim Streater
Guest
Posts: n/a
 
      09-02-2011
In article
<(E-Mail Removed)>,
cerr <(E-Mail Removed)> wrote:

> On Sep 2, 10:11*am, Tim Streater <(E-Mail Removed)> wrote:
> > In article
> > <(E-Mail Removed)>,
> >
> > *cerr <(E-Mail Removed)> wrote:
> > > Hi There,

> >
> > > I got a link as follows:
> > > <a href="xyz.com">xyz</a>
> > > and a javascript function gethtml('es') that returns the url string.
> > > Now how do i get the url string into the html link in
> > > <a href="MyString">?

> >
> > What's 'es' got to do with anything? And I would post from google
> > groups, I expect most people are filtering that out at present.

>
> I do post from google groups and why would people filter it out
> anyways?


Shitloads of spam.

--
Tim

"That excessive bail ought not to be required, nor excessive fines imposed,
nor cruel and unusual punishments inflicted" -- Bill of Rights 1689
 
Reply With Quote
 
cerr
Guest
Posts: n/a
 
      09-02-2011
On Sep 2, 11:09*am, Tim Streater <(E-Mail Removed)> wrote:
> In article
> <(E-Mail Removed)>,
>
>
>
>
>
>
>
>
>
> *cerr <(E-Mail Removed)> wrote:
> > On Sep 2, 10:11*am, Tim Streater <(E-Mail Removed)> wrote:
> > > In article
> > > <(E-Mail Removed)>,

>
> > > *cerr <(E-Mail Removed)> wrote:
> > > > Hi There,

>
> > > > I got a link as follows:
> > > > <a href="xyz.com">xyz</a>
> > > > and a javascript function gethtml('es') that returns the url string..
> > > > Now how do i get the url string into the html link in
> > > > <a href="MyString">?

>
> > > What's 'es' got to do with anything? And I would post from google
> > > groups, I expect most people are filtering that out at present.

>
> > I do post from google groups and why would people filter it out
> > anyways?

>
> Shitloads of spam.


How do I un-spam this then?
 
Reply With Quote
 
Lasse Reichstein Nielsen
Guest
Posts: n/a
 
      09-03-2011
cerr <(E-Mail Removed)> writes:

> On Sep 2, 10:11*am, Tim Streater <(E-Mail Removed)> wrote:
>> In article
>> <(E-Mail Removed)>,
>>
>> *cerr <(E-Mail Removed)> wrote:
>> > Hi There,

>>
>> > I got a link as follows:
>> > <a href="xyz.com">xyz</a>
>> > and a javascript function gethtml('es') that returns the url string.
>> > Now how do i get the url string into the html link in
>> > <a href="MyString">?

>>
>> What's 'es' got to do with anything? And I would post from google
>> groups, I expect most people are filtering that out at present.

>
> I do post from google groups and why would people filter it out
> anyways?



Because an ungodly amount of spam is comming through Google Groups,
with the current batch having subjects of the form "<Famous person>
nude", and their filtering isn't impressive (It'd probably be more
readable if forwarded through gmail, who actually does block spam
effectively).

I don't see as much medicine spam these days, so maybe they found
a way to recognize that.
/L
--
Lasse Reichstein Holst Nielsen
'Javascript frameworks is a disruptive technology'

 
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
'System.String[]' from its string representation 'String[] Array' =?Utf-8?B?UmFqZXNoIHNvbmk=?= ASP .Net 0 05-04-2006 04:29 PM
Is "String s = "abc";" equal to "String s = new String("abc");"? Bruce Sam Java 15 11-19-2004 06:03 PM
String[] files = {"a.doc, b.doc"}; VERSUS String[] files = new String[] {"a.doc, b.doc"}; Matt Java 3 09-17-2004 10:28 PM
String.replaceAll(String regex, String replacement) question Mladen Adamovic Java 3 12-05-2003 04:20 PM
Re: String.replaceAll(String regex, String replacement) question Mladen Adamovic Java 0 12-04-2003 04:40 PM



Advertisments