如何在 iframe src 中使用 javascript 变量 [英] How to use javascript variable in iframe src

查看:72
本文介绍了如何在 iframe src 中使用 javascript 变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 iframe src 中编写 javascript 变量?

how to write javascript variable in iframe src?

喜欢

<iframe id="showskill" scrolling="yes" height="350" width ="350" src="http://localhost/POSkill/skillshow.aspx?user_id="+ ReturnURL() ></iframe>

这里的 ReturnURL() 是一个返回值的 javascript 函数.但问题是在 iframe 源中我没有得到函数的返回值.是我输入的格式不正确还是遗漏了什么?

Here ReturnURL() is a javascript function which returns a value. But the problem is in the iframe source I'm not getting the returned value of the function. Am I not putting in the right format or missing something?

提前致谢约翰尼

推荐答案

您不能以这种方式直接在 html 标记中使用 JavaScript 变量或函数.你可以做的是先定义你的 iframe,然后从 JavaScript 设置它的源:

You can't use JavaScript variables or functions directly within your html markup in that manner. What you can do is define your iframe first and then set its source from JavaScript:

<iframe id="showskill" scrolling="yes" height="350" width ="350" src=""></iframe>

<script>
    document.getElementById("showskill").src =
              "http://localhost/POSkill/skillshow.aspx?user_id="+ ReturnURL();
</script>

还有其他几种方法可以实现类似的目标,但是当我不确定您的上下文是什么时,我真的不想把它们全部都讲一遍.

There are several other ways to achieve something similar, but I don't really want to go through them all when I'm not sure quite what your context is.

这篇关于如何在 iframe src 中使用 javascript 变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆