SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Sep 2002
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    using var from other functions

    I want a javascript link that acts like a normal link. I have figured out the loadUrl function, now I need to change the status bar. Can I take a varable from one function and use it in another. I don't think I can combine the functions because one needs to be called from a onclick and the other from an onmouse over.

    Code:
    function loadUrl(newLocation)
            {
                    var goTo = newLocation
                    window.location = goTo;
                    return false;
            }
    
    function hasOver()
            {
                    window.status = loadUrl.goTo;
            }
    Code:
    <a href="javascript:void" title="Rock Kills Kid"
    onclick="loadUrl('http://www.somesite.com'); return false;"
    onmouseover="hasOver(); return true;">link</a>.

  2. #2
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Certainly, but what if I mouseover the link w/o clicking on it? loadUrl.goTo won't exist!

    By the way, that loadURL() function is completely useless. All it does is do what a normal link does. Here's how to get it working best with the status line
    Code:
    <a href="http://www.somesite.com" title="Rock Kills Kid" onmouseover="showStatus( this.href );" onmouseout="showStatus('');">link</a>.
    Code:
    function showStatus( txt )
    {
        window.status = txt;
    }
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  3. #3
    SitePoint Member
    Join Date
    Sep 2002
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It is not completly useless. I need links that act like normal links to users, but are not read or used by google when my pages are spydered. This keeps my links PageRank inside my site and helps boost my site in google's searches.


    How about this code? I just want to know if this is the way to access one functions var? If not do you know how to do it? I only want to type the web URI once but have each function have access to it for what they need to do.

    Thanks //Ukiah

    Code:
    function loadUrl(newLocation)
            {
                    window.location = hasOver.goTo;
                    return false;
            }
    
    function hasOver(newLocation)
            {
                    var goTo = newLocation
                    window.status = loadUrl.goTo;
            }
    Code:
    <a href="javascript:void" title="Rock Kills Kid"
    onclick="loadUrl('http://www.somesite.com'); return false;"
    onmouseover="hasOver(); return true;">link</a>.


    No

  4. #4
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That looks like it should work. Since the mouseouver will inevitably occur before the click, that looks right.
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev





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
  •