Page 1 of 1

Block IFrames JS Code

Posted: Fri Jun 03, 2011 11:31 pm
by sacharja
Hello,

I've read about NoScript's ability to block IFrames. I desperately try to do this for Opera, however I want to filter them, based on the URL. However, I couldn't find a way to block the IFrame before it opens the specified source URL. Is NoScript able to do this? Could someone tell me where I can find the code for that in NoScript, or has an idea how to do this in JS? I only want to block external IFrames, that match these RegExp:

Code: Select all

"[?*&=,~-]http(?::|%3A)(?:\/|%2F)(?:\/|%2F)"
.

Currently I edit websites with Proxomitron, where I can block non-scripted IFrames. Then I tried to edit all JS methods, that can create IFrames (I replaced document.write, rewrote XMLHttpRequests, DOMNodeInserted...), but these may lead to further problems. If someone has a direct solution to block IFrames in JS, please help me.

Re: Block IFrames JS Code

Posted: Sat Jun 04, 2011 9:26 am
by Giorgio Maone
You can't: there are simply countless ways for a script to insert and manipulate a DOM element (obfuscation aside), therefore a proxy cannot prevent iframes from being created. You need in-browser support for that.

Re: Block IFrames JS Code

Posted: Sun Jun 05, 2011 6:13 pm
by sacharja
Thanks for the info. Then I have to disable IFrame creation. I use a code to overwrite XMLHttprequests (and to filter them). Maybe this is an additional feature for NoScript, so I post it here:

Code: Select all

XMLHttpRequest.prototype.oldOpen = XMLHttpRequest.prototype.open;

	var newOpen = function(method, url, async, user, password) {
		if (method=='GET' && url.lastIndexOf('http')<8) {this.oldOpen(method, url, async, user, password);}
	}

XMLHttpRequest.prototype.open = newOpen;
This can be extended with a blacklist/whitelist. However there is a problem with the new Google search. It's very slow. Even if you only use "this.oldOpen(method, url, async, user, password);" instead of the if loop. Typing is no longer possible in realtime in the google search box.