Mils
Mils

Reputation: 488

Passing variable to a frame using '<a...' using JavaScript

I want to pass a variable to the frame but I got the current page.

Code:

function redirect(e){
 $('#frame').show();
 document.getElementById('frame').contentWindow.document.location.href = "page.php?var="+X;         
 e.preventDefault; 
}

<a href="#"  target="frame" onClick="redirect();"></a>

Upvotes: 1

Views: 329

Answers (1)

Zach Lysobey
Zach Lysobey

Reputation: 15724

I think I may have gotten it working: http://jsfiddle.net/LrBau/1/

<a href="#" class="redirect-link">redirect</a>

<iframe id="frame"></iframe>

<script>

  var X = 'testVal';

  var redirect = function() {
    $('#frame').show().attr('src', "page.php?var=" + X);        
    return false;
  };

  $('.redirect-link').click( redirect );

</script>

Upvotes: 1

Related Questions