document.createElement() Problem

Discussion in 'JavaScript' started by Pudge1, Oct 12, 2013.

  1. #1
    
      var s = document.createElement('iframe');
      s.src= 'http://google.com'
      s.style.position = 'absolute';
      s.style.margin = '0';
      s.style.padding = '5px';
      s.style.border = '1px solid red';
     
    Code (markup):
    Here is a snippet of my JavaScript code, it works just fine creating the iFrame with the red border, etc. But it will not display Google inside of it, any one see what I'm missing here?
     
    Pudge1, Oct 12, 2013 IP
  2. malky66

    malky66 Acclaimed Member

    Messages:
    3,997
    Likes Received:
    2,248
    Best Answers:
    88
    Trophy Points:
    515
    #2
    You can't show Google in an iframe, Google sends an "X-Frame-Options: SAMEORIGIN" response header, It stops the browser from displaying iframes that are not hosted on the same domain as the parent page.
     
    malky66, Oct 12, 2013 IP
    ryan_uk and ThePHPMaster like this.
  3. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #3
    ... and of course being 2013 instead of 1998, one has to ask why you are even TRYING to use iframes in the first place, much less applying that much style from the scripting instead of the stylesheet -- but since you're trying to wrap google with it, sounds like you're already trying to do something fishy.
     
    deathshadow, Oct 14, 2013 IP