Javascript 将当前页面url传递到iframe地址

Javascript 将当前页面url传递到iframe地址,javascript,html,iframe,Javascript,Html,Iframe,你好,我想买点像 <iframe src="http://anydomain.com/frame.php?ref=http://currentpageurl.com/dir"></iframe> 对于一个纯粹的JS解决方案,这似乎正是您想要的(尽管我建议在服务器端渲染时这样做),我会这样做: <script type="text/javascript"> var iframe = document.createElement('iframe');

你好,我想买点像

<iframe src="http://anydomain.com/frame.php?ref=http://currentpageurl.com/dir"></iframe>

对于一个纯粹的JS解决方案,这似乎正是您想要的(尽管我建议在服务器端渲染时这样做),我会这样做:

<script type="text/javascript">
      var iframe = document.createElement('iframe');
      iframe.src = 'http://anydomain.com/frame.php?ref=' + window.location.href; // if you just want the path change `href` to `pathname`
      document.body.appendChild(iframe); // insert the element wherever you want in the page
</script>

var iframe=document.createElement('iframe');
iframe.src=http://anydomain.com/frame.php?ref='+window.location.href;//如果您只想将路径更改为`href`路径名`
document.body.appendChild(iframe);//在页面中任意位置插入元素

对于您想要的纯JS解决方案(尽管我建议在服务器端渲染时这样做),我会这样做:

<script type="text/javascript">
      var iframe = document.createElement('iframe');
      iframe.src = 'http://anydomain.com/frame.php?ref=' + window.location.href; // if you just want the path change `href` to `pathname`
      document.body.appendChild(iframe); // insert the element wherever you want in the page
</script>

var iframe=document.createElement('iframe');
iframe.src=http://anydomain.com/frame.php?ref='+window.location.href;//如果您只想将路径更改为`href`路径名`
document.body.appendChild(iframe);//在页面中任意位置插入元素

这是因为您的irames src是
http://localhost/ 这是因为您的irames src是
http://localhost/
<script type="text/javascript">
      var iframe = document.createElement('iframe');
      iframe.src = 'http://anydomain.com/frame.php?ref=' + window.location.href; // if you just want the path change `href` to `pathname`
      document.body.appendChild(iframe); // insert the element wherever you want in the page
</script>