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

自古美人都是妖i 提交于 2019-12-13 00:51:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!