FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


how to make links with javascript ?





manumiglani
how to make links with javascript ?
Stubru Freak
Code:
document.write("<a href='javascript:document.location.href=\'http://google.be\';'>Go here</a>");


Works better like this:
Code:
<a href='http://google.be'>Go here</a>

But it isn't javascript anymore then
manumiglani
Stubru Freak wrote:
Code:
document.write("<a href='javascript:document.location.href=\'http://google.be\';'>Go here</a>");


Works better like this:
Code:
<a href='http://google.be'>Go here</a>

But it isn't javascript anymore then


it is not totally right i think.

it shows the output

Quote:
document.write("Go here");

instead of Go here.
elekis
it's cause you forgot

<script >
..
</script>
and for search engine,the-y has a url something like that

Code:

http://www.google.be/search?q=blabla

to found blabla under google.

so if you wanna search with google by exemple
just change q= ...


a+++
manumiglani
elekis wrote:
it's cause you forgot

<script >
..
</script>
and for search engine,the-y has a url something like that

Code:

http://www.google.be/search?q=blabla

to found blabla under google.

so if you wanna search with google by exemple
just change q= ...


a+++


adding <script >
..
</script> shows the link but linked to

Quote:
javascript:document.location.href=


instead of google.be
Stubru Freak
manumiglani wrote:
elekis wrote:
it's cause you forgot

<script >
..
</script>
and for search engine,the-y has a url something like that

Code:

http://www.google.be/search?q=blabla

to found blabla under google.

so if you wanna search with google by exemple
just change q= ...


a+++


adding <script >
..
</script> shows the link but linked to

Quote:
javascript:document.location.href=


instead of google.be


Doesn't it work when you click it?

You could also just remove the javascript:document.location.href=\' and the \' at the end and just keep http://google.be
Atomo64
fixing the first code...
Stubru Freak wrote:
Code:
document.write("<a href='javascript:document.location.href=\'http://google.be\';'>Go here</a>");

should be:
Code:

<script type="text/javascript">
//<![CDATA[
document.write("<a href='#' onclick='javascript:document.location.href=\"http://google.be\";'>Go here<\/a>");
//]]>
</script>

First, when using javascript on links you have to make sure that the javascript is being used on onclick, because with browsers that doesn't support javascript would fail trying to open the link. And you can't use </ on javascript, it is because some browsers could fail and think that that's the end of the script, you have to use <\/

Stubru Freak wrote:

Works better like this:
Code:
<a href='http://google.be'>Go here</a>

But it isn't javascript anymore then

or using javascript:
Code:

<script type="text/javascript">
//<![CDATA[
document.write("<a href='http://www.google.com'>Goooooogle!<\/a>");
//]]>
</script>
manumiglani
Atomo64 wrote:
fixing the first code...
Stubru Freak wrote:
Code:
document.write("<a href='javascript:document.location.href=\'http://google.be\';'>Go here</a>");

should be:
Code:

<script type="text/javascript">
//<![CDATA[
document.write("<a href='#' onclick='javascript:document.location.href=\"http://google.be\";'>Go here<\/a>");
//]]>
</script>

First, when using javascript on links you have to make sure that the javascript is being used on onclick, because with browsers that doesn't support javascript would fail trying to open the link. And you can't use </ on javascript, it is because some browsers could fail and think that that's the end of the script, you have to use <\/

Stubru Freak wrote:

Works better like this:
Code:
<a href='http://google.be'>Go here</a>

But it isn't javascript anymore then

or using javascript:
Code:

<script type="text/javascript">
//<![CDATA[
document.write("<a href='http://www.google.com'>Goooooogle!<\/a>");
//]]>
</script>


so u provided two codes Atomo, which one i shd use if i do not want that lh\inks to be crawled by search engines ?
Atomo64
If that's what you want... none!; first, you can use robots.txt to order the robots not to index that page, you can use the <meta> tag on each page to prevent the robots from indexing that page and... and there are many other ways.,..
Ranfaroth
Most people on this thread should read this article..
Atomo64
I don't agree with some of points of that article... for example... <noscript> is commonly used for text based browsers (just as an example, because there can me more situations where you don't have JS support, as in some mobile phones), ... etc... there are just some things like the void(0) link and the href="javascript:jjj()" thing that I agree.
Related topics
session not working behind router
Links Javascript.
Complete Tutorial LINKS for every language
Script Bank Links
Programming links, info, and tutorials
CSS or Javascript?
some links with tutorials!!!
Java tutorials
JavaScript useful links
Expanding Javascript+CSS List
How to make a javascript label when you mouse over on a link
Javascript to make text links into clickable links?
help needed with css & javascript
Image Rollovers In Javascript With a Twist
Reply to topic    Frihost Forum Index -> Scripting -> Others

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.