string to href? [rookie]

C

cerr

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!
 
M

Martin Honnen

cerr said:
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.
 
T

Tim Streater

cerr said:
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.
 
C

cerr

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


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.

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
 
M

Martin Honnen

cerr said:
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.
 
C

cerr

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!
 
C

cerr

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;
}
 
L

Lasse Reichstein Nielsen

cerr said:
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
 
D

dhtml

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

dhtml

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)"
 
J

Jukka K. Korpela

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

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top