你好,我正在尝试得到类似的东西
<iframe src="http://anydomain.com/frame.php?ref=http://currentpageurl.com/dir"></iframe>
我正在使用此 HTML
<iframe src="http://localhost/
<script type="text/javascript">
document.write(window.location.pathname);
</script>
.html" frameborder="0" scrolling="no" onload="resizeIframe(this)" />
我在控制台中收到此错误
Failed to load resource: the server responded with a status of 403 (Forbidden)
GET http://localhost/%3Cscript%20type=/
最佳答案
对于一个纯粹的 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>
关于javascript - 将当前页面 url 传递给 iframe 地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36852170/