What else to use instead of iframe?

Discussion in 'HTML & Website Design' started by qwikad.com, Mar 22, 2016.

  1. #1
    iframes are being blocked by some ad blockers (as I found out). I tried to use embed and object but neither one of them works in ipads (and some iphones).

    So what other options do I have apart from iframe / embed / object?
     
    qwikad.com, Mar 22, 2016 IP
  2. make25

    make25 Greenhorn

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #2
    You could use php or Jquery load, or even Ajax, but that is just a suggestion. I won't be able to help you code that because that is beyond my current ability.

    I don't know what you are using iframe for, but maybe you could replace it with a flash object instead, so that it displays what you are wanting it to display.
     
    make25, Mar 22, 2016 IP
  3. drestauro

    drestauro Member

    Messages:
    17
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    35
    #3
    You can do something like this with Javascript, but it takes a little php to allow the javascript to call another domain by turning on Cross Origin Resource Sharing for that domain
    xhr = new XMLHttpRequest();
    xhr.onreadystatechange = function() {
      if(xhr.readystate == 4 && xhr.status == 200) {
        document.getElementById('displayDiv').innerHTML = xhr.responseText;
      }
    };
    xhr.open('GET', 'http://myIframereplacement.com/stuff?request=data', true);
    xhr.send();
    Code (markup):
    and now the PHP to allow the javascript to GET from the external domain

    <?php
    header('Access-Control-Allow-Origin: http://myIframereplacement.com');
    ?>
    Code (markup):
     
    drestauro, Mar 22, 2016 IP
  4. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #4
    My answer would be "You get NOTHING!!!" --- there's a reason we're NOT supposed to be doing that crap in the first place... If the information is on your own domain, just put it in the page normally as a part of a normal page-load, if it's not on your domain and is being nabbed by an adblock, live with it since it's probably blocking something scummy, scammy, or designed to open security holes.
     
    deathshadow, Mar 22, 2016 IP
  5. ketting00

    ketting00 Well-Known Member

    Messages:
    782
    Likes Received:
    28
    Best Answers:
    3
    Trophy Points:
    128
    #5
    Ajax won't work. I have tried it. What I can think of is canvas but implementing ad on canvas is very complicated and may violate Google terms. The simplest solution is to sell ad directly :(

    I was thinking if PHP functions like file_get_contents() can do the trick.

    I mean loading string from the other site and fired it with JavaScript. I've to try the idea. This may not work with Google adsense, however, and it may cause slow page load.
     
    ketting00, Mar 23, 2016 IP
  6. qwikad.com

    qwikad.com Illustrious Member Affiliate Manager

    Messages:
    7,259
    Likes Received:
    1,693
    Best Answers:
    31
    Trophy Points:
    475
    #6
    I found out what the culprit was. One of my folders is named "banners". Adblock plus blocks a file/folder with that name.
     
    qwikad.com, Mar 23, 2016 IP
  7. qwikad.com

    qwikad.com Illustrious Member Affiliate Manager

    Messages:
    7,259
    Likes Received:
    1,693
    Best Answers:
    31
    Trophy Points:
    475
    #7
    Are readfile and file_get_contents essentially the same? I am not using it to get a remote site / file. I am using it in the same directory. Still I was wondering which one may use less resources / cpu and which one is faster.

    
    <?php
    $file_contents = readfile('http://' . $_SERVER['HTTP_HOST'] . '/somefoldert/somefile.php');
    print $file_contents;
    ?>
    
    Code (markup):

    
    
    <?php    
    $file_contents= file_get_contents('http://' . $_SERVER['HTTP_HOST'] . '/somefoldert/somefile.php');    
    print $file_contents;
    ?>
    
    Code (markup):
     
    qwikad.com, Mar 23, 2016 IP
  8. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #8
    readfile you don't need to print. It prints/echo's all by itself. THIS:

    readfile('http://' . $_SERVER['HTTP_HOST'] . '/somefoldert/somefile.php')
    Code (markup):
    would be the same as your second code box... well, except for ONE problem.

    If that separate .php is on the same domain, the code won't run it will display it's source instead... and I don't think (I could be wrong) that readfile can even read from a separate domain. Anything you load with readfile is just shown as flat text, any PHP code inside it (or any other code for that matter) will not run on the server, PERIOD! It would just send the source of that file to the browser un-run.

    If it's php you want to run from the same directory, that's include or require's job.

    ... which is why I was sitting here wondering "Why are you dicking around with frames, ajax or file_get_contents? Just include the blasted thing!". If it's in the same directory as the running program, or even the same server, why are you wasting time with all that other nonsense?
     
    deathshadow, Mar 23, 2016 IP
  9. ketting00

    ketting00 Well-Known Member

    Messages:
    782
    Likes Received:
    28
    Best Answers:
    3
    Trophy Points:
    128
    #9
    Yes, @deathshadow is right.

    That's the job for require or include functions. I'm not sure if file_get_contents has performance penalty or improvement. I use it to fetch encoded data.

    For getting data from remote site, I see it slows enough to let adblock finishes its scanning task of get rid of those ads divs.

    That's where a light bulb pop-up in my head. I've yet to see if my theory worked.
     
    ketting00, Mar 24, 2016 IP
  10. qwikad.com

    qwikad.com Illustrious Member Affiliate Manager

    Messages:
    7,259
    Likes Received:
    1,693
    Best Answers:
    31
    Trophy Points:
    475
    #10
    I would gladly use an include if I knew how to make it work independently from the rest of the script. Everything gets messed up when I try an include. With an iframe (which I ended using LOL. See the first post.) or a file_get_contents it's easy to do. What I don't like about file_get_contents it does slow the page down. Maybe when you use just one it's not noticeable, but when you have 3-4 of them you can clearly see that it's not the best way to go.
     
    qwikad.com, Mar 24, 2016 IP
  11. ketting00

    ketting00 Well-Known Member

    Messages:
    782
    Likes Received:
    28
    Best Answers:
    3
    Trophy Points:
    128
    #11
    That should be an iframe to blame. It has been known for age that it slows page load down and was advice to be avoid. (This reminded me of the old day of flash days and Java applets :)

    Since you use it to hold ad placement, I don't think you have a choice for a while until someone come up with the idea how to solve this problem.

    Have you ever heard of PHP multi-thread? That technique should help improve your site performance significantly since it executes tasks separately and utilize all of your server CPU cores.

    I think that's the way to go for the moment, for serious developer, of course.
     
    ketting00, Mar 24, 2016 IP
  12. qwikad.com

    qwikad.com Illustrious Member Affiliate Manager

    Messages:
    7,259
    Likes Received:
    1,693
    Best Answers:
    31
    Trophy Points:
    475
    #12
    I beg to differ. I read that because file_get_contents reads a file as a string, depending on a size of that file (especially if it's a php one), it can slow a page more than an iframe. I can tell even visually that my iframes bring up content / images faster.
     
    qwikad.com, Mar 24, 2016 IP
  13. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #13
    If that's being pulled from the same domain, and the 'include' takes "so long" there is something disastrously wrong with either what's being included itself, or the page you are trying to host it from.

    THOUGH, that's why advertisements are often loaded using asynchronous javascript. Again making AJAX an even better choice depending on what you are serving given you can make it wait to load the "extra" stuff until AFTER onload for the content has fired. You could even skip the AJAX and just modify the DOM directly on the fly after load.

    I think for any of us to REALLY say anything more that's meaningful about this, we'd need to see what page you are trying to include this extra stuff on, and what it is you are trying to include. Otherwise we're all just guessing wildly in the dark.
     
    deathshadow, Mar 25, 2016 IP