Tuesday, April 5, 2011

Call an anchor tag via javascript

Hi all,

I am using thick box 3.1 to load a pop up. It working well by using in the following way:

<a href="filename.php" class="thickbox"> TEST </a>

If we click on the TEST now then the popup is working well and good.

Now my prob is: I need to call this popup in form load using JavaScript.

I do something like below:

<script type="text/javascript">

window.location.href = "filename.php"    

</script>

it's just redirecting to that particular file. But not showing in the pop up.

What is the possible way?

thanks in advance

From stackoverflow
  • Try this:

    <a href="filename.php" class="thickbox" id="openOnLoad">Test</a>
    
    <script type="text/javascript">
    $(function(){ // On DOM ready
        $('#openOnLoad').click();
    });
    </script>
    
    Fero : thanks simeon, This is what i exactly wan't. Thanks a lot man.
  • <a href="filename.php" class="thickbox" id="UniqueIdForThisLink"> TEST </a>
    
    <script type="text/javascript">
      $("#UniqueIdForThisLink").click();
    </script>
    
    Fero : thanks for your answer tomalak
    James Westgate : You're missing document.ready ...
    Tomalak : @James: Yeah... true. My focus was on using `click()` as the answer to the question, not not on making a standalone fully functional example.
  • You can do this without changing your markup, like this:

    $(function() {
      $('a[href=filename.php]').click();
    });
    
    Fero : thanks for your answer.

0 comments:

Post a Comment