...

View Full Version : Inserting Hyperlink Inside A Javascript?



tunayx
09-04-2008, 03:19 PM
I have two part of this script head and body sections. I want to insert hyperlink on text "Prices correct as at:" section so when clicked I take user to another page. I searched thru the web and internal search of the forum but can't find the solution.


<head>
<script type="text/javascript">

function getLastMod() {
var myFrm = document.getElementById('myIframe');
var lm = new Date(myFrm.contentWindow.document.lastModified);
var dt = lm.getDate();
var mm = lm.getMonth() + 1;
var yy = lm.getFullYear();
var lmDate = mm + "-" + dt + "-" + yy;
document.getElementById('LastModified').innerHTML = "Prices correct as at: " + lmDate;
}

</script>
</head>



<body>
<span id="LastModified"></span>

<iframe id="myIframe" onload="getLastMod()" src="prices.txt" style="display:none;">
</iframe>

</body>
</html>

Bill Posters
09-04-2008, 03:48 PM
document.getElementById('LastModified').innerHTML = '<a href="destination.html">Prices correct as at: </a>' + lmDate;

document.getElementById('LastModified').innerHTML = '<a href="destination.html">Prices correct as at: ' + lmDate + '</a>';

tunayx
09-04-2008, 04:02 PM
Both didn't worked..

Philip M
09-04-2008, 04:20 PM
Well, it works for me.

Make sure that the url is correctly specified as an absolute address:-

document.getElementById('LastModified').innerHTML = '<a href="http://www.yoursite.com/index.html">Prices correct as at:</a>' + " " + lmDate;


I have nothing but confidence in you. And very little of that.
Groucho Marx (1890 - 1977)

tunayx
09-04-2008, 04:44 PM
I upload it to my site you can see it's not working.

"Prices correct as at:" text is at the bottom right corner of the moon

http://www.aymavisi.org

Philip M
09-04-2008, 04:51 PM
I upload it to my site you can see it's not working.

"Prices correct as at:" text is at the bottom right corner of the moon

http://www.aymavisi.org

It works for me in IE6 (but for some reason it says "Prices correct at 3-9-2008 when today is the 4th).

When I click the link a new window opens with Destek Olun in a red box upper right.

tunayx
09-04-2008, 05:00 PM
Hmm you're right about ie, I was using Opera and it does not show any link. Date is for last updated date of a different page it's correct. You clicked the word "Neden" you should have clicked on "Prices correct at"

But your code also does not work on ff 3.0 I need a solution for this.

Bill Posters
09-04-2008, 05:15 PM
Checking the DOM in FF3, the anchor is being inserted correctly, so the code should work.

When good code doesn't appear to work, it generally means there's an issue elsewhere in your code which is causing the problem.

Forgive me for saying, but the quality of the code on that site is particularly poor.

A good place to start would be fixing the invalidations in your markup (and probably your css).
http://validator.w3.org/check?verbose=1&uri=http&#37;3A%2F%2Fwww.aymavisi.org%2Fana.html


I recommend reading the article linked in my post signature below.

tunayx
09-04-2008, 05:43 PM
In my site there's lots of codes and all worked fine except this code.

And other thing: I valitaded Google and that site has found 74 Errors, 12 warning(s) errors for Google. How can anybody explain it?

http://validator.w3.org/check?uri=http&#37;3A%2F%2Fwww.google.com%2F&charset=%28detect+automatically%29&doctype=Inline&group=0&verbose=1&user-agent=W3C_Validator%2F1.591

Philip M
09-04-2008, 05:51 PM
In my site there's lots of codes and all worked fine except this code.

And other thing: I valitaded Google and that site has found 74 Errors, 12 warning(s) errors for Google. How can anybody explain it?

http://validator.w3.org/check?uri=http&#37;3A%2F%2Fwww.google.com%2F&charset=%28detect+automatically%29&doctype=Inline&group=0&verbose=1&user-agent=W3C_Validator%2F1.591

As Bill Posters has already remarked:-

"Forgive me for saying, but the quality of the code on that site is particularly poor."

But perhaps that is better than it used to be! :D:D

Bill Posters
09-04-2008, 06:16 PM
In my site there's lots of codes and all worked fine except this code.

And other thing: I valitaded Google and that site has found 74 Errors, 12 warning(s) errors for Google. How can anybody explain it?
…and the moment something didn't work in a popular browser, they'd quite willingly check and double-check their code, making their code valid if invalidity was found to be the cause of a problem.


Believe me when I say that you're not the first to hold up Google as some kind of evidence that valid code is a nonsense - and that, therefore, invalid code can't be the reason that their site is broken. (If I'm honest, it's a bit of a newbie remark.)
Sometimes, they're right, but very often they're wrong. When IE appears to get it right and stricter browsers don't, then that suggests even more strongly that code invalidity (or malformedness) may be the root of the problem.

One way to rule out invalidity and malformedness as the cause of the problem is to make your code well-formed and valid.

I'm loathe to even get further into this debate, but I'll simply urge you one again to read the article to which I link in my signature.
It may well save us both from wasting my time.

You may not appreciate it now, but this is helpful advice.


Fwiw, there are numerous other problems and potential problems with both the site design and the approach used regarding the coding.
However, in all frankness, until you appear more receptive to the advice that has already being given, there's little incentive to spend my time offering more.

tunayx
09-04-2008, 07:08 PM
I think I identify the problem but I need help for fix it.
In ff when I look view source I see "<a" not closed with ">" but in IE it's okay how to correct this for ff.

document.getElementById('LastModified').innerHTML = '<a href="http://www.aymavisi.org/1yeniler.html"> Son G&#252;ncelleme: </a' + " " + lmDate;}


Another thing validator reccommended me to doc type I added it and google ads plus the "Prices correct as at:" text has gone?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">

Bill Posters
09-04-2008, 07:27 PM
There are so many mistakes in your code, any of which might be causing the problem. I'm not willing to debug your entire code.
(I take it that you're new to web development.)

If you aren't going to sort out the validation issues - or aren't even going to read the article which I suggested that you read - then frankly, I'm finished helping.

Hopefully someone else will be along soon to help you.

The js I posted is correct and should work. As said, if it isn't, then it's quite likely that it's being prevented from working by errors elsewhere in your code.


Good luck, sincerely.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum