问题
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>
回答1:
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>
来源:https://stackoverflow.com/questions/14982625/passing-variable-to-a-frame-using-a-using-javascript