简体   繁体   English

在iframe中传递javascript变量

[英]passing javascript variable in iframe

i am trying to pass javascript variable in iframe 我试图在iframe中传递javascript变量

here is index.html in first domain 这是第一个域中的index.html

 <script>var details ='test999'</script>;
 <iframe src="http://somedomain.com/99.html" frameborder="0" width="100%" ;scrolling="yes""></iframe>

and in other domain i am uploading 99.html with below code 在其他域中,我正在使用以下代码上传99.html

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>

<script>
  $(document).ready(function() {
    $("#prithere").html('' + details + '');
  });
</script>

<div id="prithere"></div>

i am not getting cross origin issue i am getting this undefined error. 我没有跨源问题,但是我得到了这个未定义的错误。 Uncaught ReferenceError: details is not defined is this because code is executed before iframe is loaded? 未捕获的ReferenceError:未定义详细信息是因为在加载iframe之前执行了代码? if so any solution ? 如果有什么解决办法? i cant use onclick 我不能使用onclick

IF you could, it would be parent.details but just pass it to the page: 如果可以的话,它将是parent.details但只需将其传递给页面即可:

<script>
var details ='test999'; 
document.write('<iframe src="http://somedomain.com/99.html#details='+details+'"....</iframe>');
</script>

Then 然后

$(document).ready(function() {
  $("#prithere").html(location.hash.split("details=")[1]);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM