HTML, set iframe src as a javascript variable

喜夏-厌秋 提交于 2019-12-24 03:10:30

问题


I would like to display a window in my webpage of another webpage, hopefully via iframe. I need to set the src as a javascript variable, here is the code:

<html>
<head><title>my webpage</title></head>
<SCRIPT language=JavaScript type=text/javascript>
function GoToURL(j) {
var URLis = document.URLframe.Dest.value
document.write("<center><iframe src=\"http://www.example.com\"/ width=1350 height=500     seamless></center>");
    }
</SCRIPT>
<FORM name=URLframe>
<TABLE align=center border=0>

<TBODY>
<TR>
<TD vAlign=center align=middle><BR><INPUT maxLength=50 size=50 
  name=Dest></TD></TR>
<TR>
<TD align=middle>
  <P><INPUT onclick=GoToURL(this) type=button value="                       Go to..                                " name="Go to"></P></TD></TR></TBODY></TABLE></FORM>
</html>

I need to set the iframe src to the variable URLis, simply put. I am somewhat of a newb in both html and javascript, so please keep as simple as possible. Do you have any suggestions or ideas for a way to set the iframe src as URLis variable?

Thank you.


回答1:


Try this:

var URLis = document.URLframe.Dest.value;
document.write('<center><iframe src="' + URLis + '" width=1350 height=500 seamless></center>');


来源:https://stackoverflow.com/questions/13654868/html-set-iframe-src-as-a-javascript-variable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!