IE5-7 時代,CSS expression() 允許在樣式中執行 JavaScript,有人嘗試用它阻擋惡意 iframe 與外部腳本注入(俗稱「掛馬」)。以下五種方案純屬歷史產物,**現代瀏覽器均不支援**,且存在嚴重效能與安全風險。
iframe { n1ifm: expression(this.src='about:blank', this.outerHTML=''); }
script { nojs1: expression((this.src.toLowerCase().indexOf('http')==0)? document.write('木馬被成功隔離!') : ''); }
iframe { nifm2: expression(this.src='about:blank', this.outerHTML=''); }
script { no2js: expression((this.src.toLowerCase().indexOf('http')==0)? document.close() : ''); }
iframe { ni3fm: expression(this.src='about:blank', this.outerHTML=''); }
script { n3ojs: expression((this.src.toLowerCase().indexOf('http')==0)? document.execCommand('stop') : ''); }
iframe { nif4m: expression(this.src='about:blank', this.outerHTML=''); }
script { noj4s: expression(if(this.src.indexOf('http')==0) this.src='res://ieframe.dll/dnserror.htm'); }
iframe { nifm5: expression(this.src='about:blank', this.outerHTML=''); }
script { noj5s: expression((this.id.toLowerCase().indexOf('vok')!=-1)? document.write('木馬被成功隔離!') : ''); }
HTML 需加白名單 id:<script src="..." id="lhSearchJSapi"></script>。
expression() 僅 IE5-7 支援,IE8+ 已移除。script-src 'self' https://trusted.cdn.com; 禁止內聯腳本與非信任來源。<script src="..." integrity="sha384-..." crossorigin="anonymous"> 確保第三方資源未被篡改。<iframe sandbox="allow-scripts allow-same-origin"> 限制權限。