javascript - Hide iframe if src is http:// without link -


i need hide iframe if

src "http://".  

what tried do:

<script type="text/javascript">      if ( $('iframe[src][src="http://"]') )         document.getelementbyid('iframe').style.display='none';     else         document.getelementbyid('iframe').style.display='block'; </script> 

and html

<iframe id="iframe" src="url" ></iframe> 

if want hide iframes src="http://", can jquery , regex.

note: in chrome, src of "http://" reported "http:". in safari , chrome on ios reported "http:/". account difference simple regex can used.

$('iframe').each(function() {    var src = this.src.tolowercase();    if (/^http:[\/]{0,2}$/i.test(src)) {      $(this).hide();    } else {      $(this).show();    }  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>  1. http://<br><iframe id="iframe" src="http://"></iframe><br>  2. http://blog.stackoverflow.com/wp-content/uploads/stackoverflow-logo-300.png<br><iframe id="iframe" src="http://blog.stackoverflow.com/wp-content/uploads/stackoverflow-logo-300.png"></iframe><br>


if additionally want hide iframes src="" or no src set, or src="https://", can use code below. conditional src === self.location.href tests src="". regex /^https?:[\/]{0,2}\w/i tests "http(s)://" plus 1 word character. if not found, iframe hidden. non-http(s) src'd iframes hidden too.

$('iframe').each(function() {    var src = this.src.tolowercase();    if (src === self.location.href || !/^https?:[\/]{0,2}\w/i.test(src)) {      $(this).hide();    } else {      $(this).show();    }  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>  1. http://<br><iframe id="iframe" src="http://"></iframe><br>  2. https://<br><iframe id="iframe" src="https://"></iframe><br>  3. http://blog.stackoverflow.com/wp-content/uploads/stackoverflow-logo-300.png<br><iframe id="iframe" src="http://blog.stackoverflow.com/wp-content/uploads/stackoverflow-logo-300.png"></iframe><br>  4. ""<br><iframe id="iframe" src=""></iframe><br>  5. (blank)<br><iframe id="iframe"></iframe><br>  6. "a.htm"<br><iframe id="iframe" src="a.htm"></iframe><br>  7. src<br><iframe id="iframe" src></iframe><br>


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -