Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13
  1. #1
    New Coder
    Join Date
    Apr 2007
    Posts
    60
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Inserting Hyperlink Inside A Javascript?

    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>

  • #2
    Senior Coder
    Join Date
    Feb 2003
    Posts
    1,665
    Thanks
    0
    Thanked 27 Times in 25 Posts
    Code:
    document.getElementById('LastModified').innerHTML = '<a href="destination.html">Prices correct as at: </a>' + lmDate;
    Code:
    document.getElementById('LastModified').innerHTML = '<a href="destination.html">Prices correct as at: ' + lmDate + '</a>';

  • #3
    New Coder
    Join Date
    Apr 2007
    Posts
    60
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Both didn't worked..

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,080
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    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)
    Last edited by Philip M; 09-04-2008 at 03:24 PM.

  • #5
    New Coder
    Join Date
    Apr 2007
    Posts
    60
    Thanks
    3
    Thanked 0 Times in 0 Posts
    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

  • #6
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,080
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Quote Originally Posted by tunayx View Post
    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.

  • #7
    New Coder
    Join Date
    Apr 2007
    Posts
    60
    Thanks
    3
    Thanked 0 Times in 0 Posts
    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.

  • #8
    Senior Coder
    Join Date
    Feb 2003
    Posts
    1,665
    Thanks
    0
    Thanked 27 Times in 25 Posts
    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?verbos...org%2Fana.html


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

  • #9
    New Coder
    Join Date
    Apr 2007
    Posts
    60
    Thanks
    3
    Thanked 0 Times in 0 Posts
    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=ht...idator%2F1.591

  • #10
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,080
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Quote Originally Posted by tunayx View Post
    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=ht...idator%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!
    Last edited by Philip M; 09-04-2008 at 04:53 PM.

  • #11
    Senior Coder
    Join Date
    Feb 2003
    Posts
    1,665
    Thanks
    0
    Thanked 27 Times in 25 Posts
    Quote Originally Posted by tunayx View Post
    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.
    Last edited by Bill Posters; 09-04-2008 at 05:25 PM.

  • #12
    New Coder
    Join Date
    Apr 2007
    Posts
    60
    Thanks
    3
    Thanked 0 Times in 0 Posts
    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">
    Last edited by tunayx; 09-04-2008 at 06:24 PM.

  • #13
    Senior Coder
    Join Date
    Feb 2003
    Posts
    1,665
    Thanks
    0
    Thanked 27 Times in 25 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •