2
votes

I want to add JavaScript links to any site urls with iframe. But it returns error like this.

"Uncaught SecurityError: Failed to read the 'contentDocument' property from 'HTMLIFrameElement': Blocked a frame"

I tried it with javascript.

    $('iframe').contents().find('head').append(created_script);
        created_script=document.createElement('script');
    created_script.src='http://tag-test-super-star.c9users.io/server/js/index.js';
    created_script.type='text/javascript';
    $('.iframe_tag').contents().find('head').append(created_script);

I think there will be solution with php. Is there any?

3

3 Answers

2
votes

The Same Origin Policy prevents you from touching other domains. Heck sites can even block you from sticking your page in an iframe.

PHP is not going to do anything unless you are going to scrap the content, rewrite all of the URLs and output it on your server. Doing this is a BAD idea because if someone finds out you are doing it, they can add a script to your page that does some awesome things to it.

2
votes

This can be down to several factors, but generally speaking this will be due to security settings preventing you from writing into and out of the iFrame. There are numerous settings which prevent this in your browser, which can be disabled if you so wish, however if this is functionality that you wish to provide to other page visitors, it will likely involve them changing browser security settings to implement, and is a very bad route to follow - I would recommend finding an alternative solution.

More information: What you can and can't do with iFrames

1
votes

Please don't use iframe. Please use html dom parser instead iframe.