如何在iframe src中使用javascript变量 [英] How to use javascript variable in iframe src
问题描述
如何在iframe src中编写javascript变量?
$ b 像
< iframe id =showskillscrolling =yesheight =350width =350src =http://localhost/POSkill/skillshow.aspx?user_id =+ ReturnURL()>< ; / iframe的>
这里的ReturnURL()是一个返回值的javascript函数。但问题是在iframe源中,我没有得到函数的返回值。我没有把正确的格式或丢失的东西?
预先感谢
Johnny
您不能以这种方式在您的html标记中直接使用JavaScript变量或函数。你可以做的是先定义你的iframe,然后从JavaScript中设置它的源代码:
< iframe id =showskill滚动=yesheight =350width =350src =>< / iframe>
< script>
document.getElementById(showskill)。src =
http://localhost/POSkill/skillshow.aspx?user_id =+ ReturnURL();
< / script>
还有其他几种方法可以实现类似的效果,但我并不想通过它们所有当我不确定你的背景是什么。
how to write javascript variable in iframe src?
Like
<iframe id="showskill" scrolling="yes" height="350" width ="350" src="http://localhost/POSkill/skillshow.aspx?user_id="+ ReturnURL() ></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?
Thanks in advance Johnny
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屋!