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 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question HELP!! Converting HTML <a> tag to JAVASCRIPT

    ok, quick and to the point. I have this...

    Code:
    <a href="www.mylink.com" class="myclass">click</a>
    and I wanna change it to a javascript function that can be called via the SAME tag, but with this link:

    Code:
    <a href="javascript: myfunction()">click</a>
    Here's what i have so far:

    Code:
    <head>
    	<script type="text/javascript">
    		
    		function myfunction() 
    		     {
    		     window.location.href='www.mylink.com';
    		     }
    	</script>
    	
    </head>
    <body>
    <a href="javascript: myfunction()">click</a>
    </body>
    this works to the point where it only opens the link, but now i can't figure out how to add the class to it. I tried adding it inside the body tag, but it doesn't work. So, I'm wondering if it's possible to set the class in the javascript.

    Thanks in advance for the help, I really appreciate it

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,801
    Thanks
    160
    Thanked 2,216 Times in 2,203 Posts
    Blog Entries
    1
    Code:
    <a href="http://www.mylink.com" class="myclass" onclick="myfunction(this.href); return false;">click</a>
    Code:
    <script type="text/javascript">
    		
    		function myfunction(value) 
    		     {
    		     window.location.href=value;
    		     }
    	</script>
    btw, what's your actual goal?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    jcaraballomusic (06-21-2010)

  • #3
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question

    that almost worked! but didn't.

    sorry, i forgot to mention what it's for.

    I'm building a website and for all the pictures and images, I'm using a plugin called colorbox. When you click on a link with a certain class, in my case, "class=flashdirect" it opens the link in a javascript popup (not on a separate window, but a zoom popup within the same window.

    Now, I'm making the website so that the only thing that loads is the content under the menu, while the menu stays the same. For that I'm using an "iFrame" for all the pages in the website. So far everything is going well. The only thing is that I'm using "colorbox" within the iframe. I have it set so when I click on a thumbnail, it opens up a youtube video in a javascript popup, but the problem is that it pops up within the iframe.

    HERE'S WHERE I GET STUCK:

    I want it that when i click on the thumbnail in the iframe, it pops up on the parent page, not in the iframe.

    so my idea was to place the thumbnail tag on the parent page, but hidden, and somehow make a tag that when I click on the thumbnail inside the iframe, it opens up the thumbnail tag on the parent page.

    I hope this can help in solving my problem. Thanks so much

  • #4
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I figured it out. thanks! God bless

  • #5
    New Coder
    Join Date
    Jun 2010
    Location
    The Netherlands
    Posts
    52
    Thanks
    0
    Thanked 6 Times in 6 Posts
    I do not know how you solved this, but I'm assuming you used:
    <a href="javascript" target="_parent"><img src="img" /></a>


  •  

    Tags for this Thread

    Posting Permissions

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