Advertisement
pusatdata

IFRAME: Cara Block Popup dari web yang diiframe

Dec 27th, 2014
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. Sumber: http://stackoverflow.com/questions/4461282/how-to-block-pop-up-coming-from-iframe
  2.  
  3. If you are wanting to block something like POP up ads or something coming from a website you are showing in an IFRAME - it's fairly easy.
  4.  
  5. Make a framefilter.php and javascriptfilter.php which your iframe points to. You can modify it to meet your needs such as the onload blah blah and etc. But as/is - it's been working fine for me for quite a while. Hope it helps.
  6.  
  7. =============================================
  8. Replace your standard IFRAME HTML with this:
  9. ==============================================
  10.  
  11. <IFRAME SRC="http://www.yourdomainhere.com/framefilter.php?furl=http://www.domainname.com" WIDTH=1000 HEIGHT=500>
  12. If you can see this, your browser doesn't
  13. understand IFRAMES. However, we'll still
  14. <A HREF="http://www.domainname.com">link</A>
  15. you to the page.
  16. </IFRAME>
  17.  
  18.  
  19. ============================
  20. Framefilter.php
  21. ============================
  22.  
  23.  
  24. <?php
  25.  
  26. //Get the raw html.
  27. $furl=trim($_GET["furl"]);
  28. $raw = file_get_contents($furl);
  29.  
  30. $mydomain="http://www.yourdomainhere.com/";
  31.  
  32. //Kill anoying popups.
  33. $raw=str_replace("alert(","isNull(",$raw);
  34. $raw=str_replace("window.open","isNull",$raw);
  35. $raw=str_replace("prompt(","isNull(",$raw);
  36. $raw=str_replace("Confirm: (","isNull(",$raw);
  37.  
  38. //Modify the javascript links so they go though a filter.
  39. $raw=str_replace("script type=\"text/javascript\" src=\"","script type=\"text/javascript\" src=\"".$mydomain."javascriptfilter.php?jurl=",$raw);
  40. $raw=str_replace("script src=","script src=".$mydomain."javascriptfilter.php?jurl=",$raw);
  41.  
  42. //Or kill js files
  43. //$raw=str_replace(".js",".off",$raw);
  44.  
  45. //Put in a base domain tag so images, flash and css are certain to work.
  46. $replacethis="<head>";
  47. $replacestring="<head><base href='".$furl."/'>";
  48. $raw=str_replace($replacethis,$replacestring,$raw);
  49.  
  50. //Echo the website html to the iframe.
  51. echo $raw;
  52.  
  53. ?>
  54.  
  55.  
  56. ================================
  57. javascriptfilter.php
  58. ================================
  59.  
  60. <?php
  61.  
  62. //Get the raw html.
  63. $jurl=trim($_GET["jurl"]);
  64. $raw = file_get_contents($jurl);
  65.  
  66. //Note, if trickyness like decode detected then display empty.
  67. if(!preg_match("decode(", $raw)){
  68.  
  69. //Kill anoying popups.
  70. $raw=str_replace("alert(","isNull(",$raw);
  71. $raw=str_replace("window.open","isNull",$raw);
  72. $raw=str_replace("prompt(","isNull(",$raw);
  73. $raw=str_replace("Confirm: (","isNull(",$raw);
  74.  
  75. //Echo the website html to the iframe.
  76. echo $raw;
  77.  
  78. }
  79.  
  80. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement