SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Zealot themissingelf's Avatar
    Join Date
    Nov 2001
    Location
    UK
    Posts
    165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Not calling the function...

    I have this in my page:
    Code:
    <script src="scripts/jscript.js" language=javascript type="text/javascript">
    LinkToMainSite();
    </script>
    And this in my external .js file:
    Code:
    function linkToMainSite() {
     if (window.name != 'newWin') {
     document.write('<a href="<A href='http://www.aurl.co.uk">Visit'>http://www.aurl.co.uk">Visit home page</a>');
     }
    }
    But nothing happens. I don't get the expected "Visit Home Page" link in the main page.

    The script works fine when embedded into the page itself, it's just when it is in the external file that it stops working.

    Any thoughts?

    Cheers

  2. #2
    Under Construction Poop_Shoot's Avatar
    Join Date
    Jul 2003
    Location
    Sacramento, CA
    Posts
    330
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try this


    <script src="scripts/jscript.js" language="javascript" type="text/javascript"> </script>

    <script>
    LinkToMainSite();
    </script>

    Add some quotes around your language attribute also!

  3. #3
    SitePoint Zealot themissingelf's Avatar
    Join Date
    Nov 2001
    Location
    UK
    Posts
    165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Still does not work. However, I now get an error message. Mozilla says LinkToMainSite is not defined.

    BTW - thanks for the tip about the quotes...

  4. #4
    SitePoint Zealot themissingelf's Avatar
    Join Date
    Nov 2001
    Location
    UK
    Posts
    165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I accidentally stumbled upon another solution to my original problem. The idea behind the script was to ensure that any visitor reaching the site via a popup window (i.e. if the popup were returned in their search results) would get to visit the home page.

    I've now tied the window.name check to the body onLoad and, if it's not named "newWin", then they a linked straight on the home page.

  5. #5
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    LinkToMainSite() != linkToMainSite();

    also, the quotes here are wrong (and why do you have an href within an href?):

    Code:
    '<a href="<A href='http://www.aurl.co.uk">Visit'>http://www.aurl.co.uk">Visit home page</a>');


    Code:
    if (window.name != 'newWin')
    {
     document.write('<a href = "http://www.aurl.co.uk">Visit home page</a>'); 
    } 


    Vinny
    Where the World Once Stood
    the blades of grass
    cut me still

  6. #6
    SitePoint Zealot themissingelf's Avatar
    Join Date
    Nov 2001
    Location
    UK
    Posts
    165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cheers, Vinny.
    I noticed the "L" != "l" but it still do not make it work.

    The HREF within an HREF - A bit of a cut and paste gaff. Ooops.

  7. #7
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    so, what does the code look like now?
    and is it still a problem?
    Vinny
    Where the World Once Stood
    the blades of grass
    cut me still


Bookmarks

Posting Permissions

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