Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript document.createElement(“iframe”)不工作_Javascript - Fatal编程技术网

Javascript document.createElement(“iframe”)不工作

Javascript document.createElement(“iframe”)不工作,javascript,Javascript,我继承了一些JS代码,要求我修改这些代码以调用网页并将其插入iframe。我以前问过这个问题,得到了一段代码,它本身没有任何作用。我将它插入到JS代码中,但我缺少的是如何执行它。我正在学习JS,所以我相信答案可能相当简单。我得到的代码是: document.addEventListener('keydown',function(e){ //SHIFT + something if(e.altKey){ switch(e.code){ case 'KeyA': &l

我继承了一些JS代码,要求我修改这些代码以调用网页并将其插入iframe。我以前问过这个问题,得到了一段代码,它本身没有任何作用。我将它插入到JS代码中,但我缺少的是如何执行它。我正在学习JS,所以我相信答案可能相当简单。我得到的代码是:

document.addEventListener('keydown',function(e){

 //SHIFT + something
  if(e.altKey){
  switch(e.code){

  case 'KeyA':        <----- this works fine and invokes the appropriate website
    window.location = "http://www.website1.com/graphics/webpage4.html";
    break;

  case 'KeyZ':        <----- this section does nothing that I can see with this code 
    function prepareFrame() {
    var ifrm = document.createElement("iframe");
    ifrm.setAttribute("src", "http://www.website1/graphics/webpage4.html");
    ifrm.style.width = "640px";
    ifrm.style.height = "480px";
    document.body.appendChild(ifrm);
    }

    break;
    
    
}
document.addEventListener('keydown',函数(e){
//移位+某物
如果(如altKey){
开关(e.code){

case'KeyA':它什么也不做,因为它只声明
prepareFrame
函数,不调用它

case'KeyZ':
函数prepareFrame(){
// ...
}
prepareFrame()
打破

它什么也不做,因为它只声明
prepareFrame
函数,不调用它

case'KeyZ':
函数prepareFrame(){
// ...
}
prepareFrame()
打破