string to href? [rookie]

Discussion in 'Javascript' started by cerr, Sep 2, 2011.

  1. cerr

    cerr Guest

    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!
    cerr, Sep 2, 2011
    #1
    1. Advertising

  2. 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/
    Martin Honnen, Sep 2, 2011
    #2
    1. Advertising

  3. cerr

    Tim Streater Guest

    In article
    <>,
    cerr <> 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
    Tim Streater, Sep 2, 2011
    #3
  4. cerr

    cerr Guest

    On Sep 2, 10:06 am, Martin Honnen <> 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
    cerr, Sep 2, 2011
    #4
  5. 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/
    Martin Honnen, Sep 2, 2011
    #5
  6. cerr

    cerr Guest

    On Sep 2, 10:36 am, Martin Honnen <> 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!
    cerr, Sep 2, 2011
    #6
  7. cerr

    cerr Guest

    On Sep 2, 10:11 am, Tim Streater <> wrote:
    > In article
    > <>,
    >
    >  cerr <> 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? :eek:

    '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;
    }
    cerr, Sep 2, 2011
    #7
  8. cerr

    Tim Streater Guest

    In article
    <>,
    cerr <> wrote:

    > On Sep 2, 10:11 am, Tim Streater <> wrote:
    > > In article
    > > <>,
    > >
    > >  cerr <> 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? :eek:


    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
    Tim Streater, Sep 2, 2011
    #8
  9. cerr

    cerr Guest

    On Sep 2, 11:09 am, Tim Streater <> wrote:
    > In article
    > <>,
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >  cerr <> wrote:
    > > On Sep 2, 10:11 am, Tim Streater <> wrote:
    > > > In article
    > > > <>,

    >
    > > >  cerr <> 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? :eek:

    >
    > Shitloads of spam.


    How do I un-spam this then?
    cerr, Sep 2, 2011
    #9
  10. cerr <> writes:

    > On Sep 2, 10:11 am, Tim Streater <> wrote:
    >> In article
    >> <>,
    >>
    >>  cerr <> 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? :eek:



    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'
    Lasse Reichstein Nielsen, Sep 3, 2011
    #10
  11. cerr

    dhtml Guest

    On Sep 2, 11:02 am, cerr <> wrote:
    > On Sep 2, 10:11 am, Tim Streater <> wrote:
    >
    > > In article
    > > <>,

    >
    > >  cerr <> 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? :eek:
    >
    > '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;
    >
    >

    Just use a link; don't use js for that. E.g.
    <a href="/en_us/">American English</a>
    --
    Garrett
    dhtml, Sep 8, 2011
    #11
  12. cerr

    dhtml Guest

    On Sep 3, 2:36 am, Lasse Reichstein Nielsen <>
    wrote:
    > cerr <> writes:
    > > On Sep 2, 10:11 am, Tim Streater <> wrote:
    > >> In article
    > >> <>,

    >
    > >>  cerr <> 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? :eek:

    >
    > 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.

    They got their viagra now they need some pornz.
    --
    Garrett
    dhtml, Sep 8, 2011
    #12
  13. cerr

    dhtml Guest

    On Sep 2, 10:36 am, Martin Honnen <> 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.
    > 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.
    >

    It's a bad idea. Can be quite annoying when it fails. It's as bad as
    using javascript to submit forms and if you have used the web at all,
    you know how annoying that can be. Here's a great example of that
    failing:
    http://blogs.msdn.com/b/ie/archive/2011/08/31/browsing-without-plug-ins.aspx#10205082

    "I can't post a link to the comments that were lost (e.g. they weren't
    lost after being successfully added - they were never accepted/
    received by the system)"
    dhtml, Sep 8, 2011
    #13
  14. 2.9.2011 21:02, cerr wrote:

    >>> 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">?

    [...]
    > '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;
    > }


    People seem to have had difficulties in understanding what you're doing,
    but having seen situations where such operations may make sense, I'm
    taking a guess: You have a page with local (relative) links, and you
    would like to rewrite some of those links so that they are replaced by
    absolute links with a part that selects a particular language. The
    specifics still aren't clear at all (a real URL would have helped a lot,
    as usual), and I doubt whether this is one of the rare cases where the
    approach makes sense, but...

    ....you need some way of selecting the link(s) to be changed, and then
    you just do something like
    foo.href = gethtml('es') + foo.href
    where foo is a variable referring to an element.

    Oh wait... you have written "xyz.com", which _is_ a relative link, but
    maybe you actually meant "http://xyz.com", referring to an external
    site. Then I don't see why your gethtml() takes the _current_ page URL
    (window.location.href) as the starting point.

    --
    Yucca, http://www.cs.tut.fi/~jkorpela/
    Jukka K. Korpela, Sep 8, 2011
    #14
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. CRON
    Replies:
    24
    Views:
    200,462
    Adrienne Boswell
    Jun 20, 2006
  2. Soren Vejrum
    Replies:
    4
    Views:
    528
    Lasse Reichstein Nielsen
    Jul 5, 2003
  3. saiho.yuen
    Replies:
    3
    Views:
    410
    kaeli
    Sep 14, 2004
  4. Replies:
    2
    Views:
    444
  5. Vincent van Beveren

    BASE HREF and A HREF="#" onclick="..."

    Vincent van Beveren, Jul 6, 2006, in forum: Javascript
    Replies:
    2
    Views:
    295
    Vincent van Beveren
    Jul 6, 2006
Loading...

Share This Page