How to inject a JavaScript function and its call from text area? [closed]
How can I submit a function definition and its call from
<input type="text">
tag?
EDIT: My friend have written a php script where he takes the value of tag and without calling strip_tags function prints on another page. Now 开发者_StackOverflow中文版I want to show an example with JavaScript (I believe it should be possible) that I can inject a JavaScript code into his website. That is my task.
If you want to invoke script from your textbox, try to use eval
in javascript.
<script type="text/javascript">
function Invoke()
{
var ctrl = document.getElementById('content')
eval(ctrl.value);
}
</script>
<input type="text" id="content" />
<input type="button" onclick="Invoke()" value="Invoke" />
Code: http://jsfiddle.net/AuPRM/
Assign the return value of yourFunction.toString()
to the value
property of the field.
精彩评论