0

I have a JS file from which I want to call an html file and put it in an iframe. In html, to get it to work, I use:

<iframe src="WebPage1.html"
  frameborder="0" 
  marginheight="0" 
  marginwidth="0" 
  width="100%" 
  height="100%" 
  scrolling="auto"
</iframe>

I am looking for how I would make a similar call within the JS file. This is the code in the JS file:

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

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

      case 'KeyB':
        window.location = "http://www.mysite1.com";  <--- I want to call this using iframe
        break;
        
      case 'KeyC':
        window.location = "http://www.mysite2.com";      <--- I want to call this using iframe
        break;

      case 'KeyT':
        window.location = "http://www.mysite3.com";   <--- I want to call this using iframe
        break;
 
      case 'KeyW':
        window.location = "http://www.mysite4.com";  <--- I want to call this using iframe
        break;
                
    }
  }
CNE
  • 63
  • 1
  • 7
  • Set the `iframe` `src` attribute to the appropriate url. `document.getElementsByTagName("iframe")[0].src = yourUrl;` `window.location` will navigate your current page to the url provided – Ryan Wilson Mar 07 '21 at 01:00
  • 1
    Does this answer your question? [Creating an IFRAME using JavaScript](https://stackoverflow.com/questions/8726455/creating-an-iframe-using-javascript) – steven7mwesigwa Mar 07 '21 at 01:18

0 Answers0