Rich5757 Rich5757 - 1 year ago 83
jQuery Question

Get all Iframe tag inside a textarea having src as http using jquery

I have a textarea with id 'description', User can place as many iframe inside it, I want when user clicks on submit button system scan all Iframes and if there is any iframe which src is http system show an alert message that Iframe src from http site are not allowed. If Iframe src is https then its ok.

I am trying below code

var content = jQuery('#description').val();

But its not working.

Please help


Answer Source

Try wrapping you content in a div and then perform find

        var content = jQuery('#description').val();
        if ($('<div>'+content+'</div>').find('iframe[src^="http:"]').length > 0) {
          alert('Iframes over http aren't allowed ');     
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download