Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable JavaScript in iframe/div

I am making a small HTML page editor. The editor loads a file into an iframe. From there, it could add, modify, or delete the elements on the page with new attributes, styles, etc. The problem with this, is that JavaScript (and/or other programming languages) can completely modify the page when it loads, before you start editing the elements. So when you save, it won't save the original markup, but the modified page + your changes.

So, I need some way to disable the JavaScript on the iframe, or somehow remove all the JavaScript before the JavaScript starts modifying the page. (I figure I'll have to end up parsing the file for PHP, but that shouldn't be too hard) I considered writing a script to loop through all the elements, removing any tags, onclick's, onfocus's, onmouseover's, etc. But that would be a real pain.

Does anyone know of an easier way to get rid of JavaScript from running inside an iframe?

UPDATE: unless I've missed something, I believe there is no way to simply 'disable JavaScript.' Please correct me if I'm wrong. But, I guess the only way to do it would be to parse out any script tags and JavaScript events (click, mouseover, etc) from a requested page string.

like image 278
Azmisov Avatar asked Sep 11 '10 01:09

Azmisov


People also ask

How do I turn off iframe?

Probably the best bet is to set the src attribute to blank, but this will make the iframe blank, not blurred. setting the src to blank would hide the content of the iframe.

How do I disable JavaScript in HTML?

Press Control+Shift+P or Command+Shift+P (Mac) to open the Command Menu. Start typing javascript , select Disable JavaScript, and then press Enter to run the command. JavaScript is now disabled.

How do I turn off iframe clicks?

Typically, clicking on elements is disabled by using Javascript to set the element's "onclick" event to "return false." Unfortunately, there is no onclick event for iframe elements. However, clicking can still be disabled by placing an invisible blocking overlay over the iframe.

Can an iframe run JavaScript?

Calling a parent JS function from iframe is possible, but only when both the parent and the page loaded in the iframe are from same domain i.e. example.com , and both are using same protocol i.e. both are either on http:// or https:// .


1 Answers

HTML5 introduces the sandbox attribute on the iframe that, if empty, disables JavaScript loading and execution.

like image 52
AlexanderB Avatar answered Oct 04 '22 14:10

AlexanderB