Here's a sample code:
HTML
<script> alert('This is alert!') </script>
JS
window.alert = function(data) //alert() over-riding
{
scriptObject = document.currentScript; //gives me <script> object
}
Update: The above code doesn't seem to work now (It worked earlier, compatibility removed for IE) in Internet Explorer 11.420.10586.0. Why it is able to find the Script object in Chrome, Firefox, Safari and Microsoft Edge, but not in Internet Explorer? Is there any alternate way?
Issue:
HTML
<script> ReferenceError.prototype.__defineGetter__('name', function fff() { javascript:alert(1) }),x </script>
JS
window.alert = function(data) //alert() over-riding
{
scriptObject = ? // I need to get the Script object
}
I tried arguments.callee.caller
to find fff()
, but unable to catch the script object.
Alert() doesn't execute in Chrome for the above script. Use Firefox, instead. I couldn't get the script object in any browser.
Any solution please?
Select the HTML element which need to remove. Use JavaScript remove() and removeChild() method to remove the element from the HTML document.
Use document. document. currentScript will return the <script> element whose script is currently being processed.
You can place any number of scripts in an HTML document. Scripts can be placed in the <body> , or in the <head> section of an HTML page, or in both.
The window. navigator object contains information about the visitor's browser.
In the simplest scenario when your overridden alert
is invoked immediately in (blocking) script, simple document.scripts[document.scripts.length-1]
could be good to go:
<pre id="log"></pre>
<script>
window.alert = function(a){
log.innerText += a + ' ' + document.scripts[document.scripts.length-1].outerHTML + '\n';
}
</script>
<script id="a">alert('first')</script>
<script id="b">alert('second')</script>
<script id="c">alert('third')</script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With