简体   繁体   中英

Remove all content between <script type=“JavaScript”>abcd</script> tags

I want to remove all things or content between <script>want to remove</script> I have very small amount of knowledge about php & java script so please give me a complete codes I have no idea how to use php or JavaScript coding to remove content between <tags></tags>

I found this box and copy in my website they remove all tags but I not want this I want only remove content between tags. Please any one modify this box or script to remove content between <tags></tags> or give me other script.

<script type="text/javascript">

// Strip HTML Tags (form) script- By JavaScriptKit.com (http://www.javascriptkit.com)
// For this and over 400+ free scripts, visit JavaScript Kit- http://www.javascriptkit.com/
// This notice must stay intact for use

function stripHTML(){
var re= /<\S[^><]*>/g
for (i=0; i<arguments.length; i++)
arguments[i].value=arguments[i].value.replace(re, "")
}

</script>

<form>

<textarea name="data1" style="width: 400px; height: 100px"></textarea><br />
<input type="button" value="Remove any HTML tags" onClick="stripHTML(this.form.data1)">
</form>

你可以尝试:document.getElementsByTagName('script')[0] .innerHTML ='';

According to your code block you posted, it seems that you would like to strip script tags from the value of a form element (eg a textarea). Sanitizing user input on client side is generally considered to be a bad idea, because this kind of security measure can be easily bypassed. A better solution would be stripping the script tags from the posted data on the server side.

Here is an example in php:

$data = $_POST['fieldname'];

$outputData = strip_tags($data, array(/* here you can specify the allowed html tags, all others will be stripped */);

echo $output;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM