Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8991251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:40:59+00:00 2026-06-15T22:40:59+00:00

I want to display html provided by a user in a page. My page

  • 0

I want to display html provided by a user in a page. My page is almost entirely dynamic (JS code), and I was wondering if there’s an easy way to sanitize it?

Like, maybe I could remove all the <script> and <iframe> tags and unbind all the events contained in the string (or remove any html attribute starting by ‘on’) in order to not have any javascript code from the string possibly executed?

Can the users possibly insert javascript with a css ‘content’ property in a style attribute?

The jquery $(...).text(...) function doesn’t help me, since I want to preserve any html mark-up or css styling.

If there’s no easy solution i’m ready to live with a whitelist of html tags (table span div img a b u i strong…), but i’d rather not have to white-list the attributes too.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T22:41:00+00:00Added an answer on June 15, 2026 at 10:41 pm

    The more foolproof way to show user content safely is to embed it in an iframe who’s origin is a different domain than your host web page. This is what jsFiddle does. The main page is served from jsfiddle.net, but the user scripts are served from fiddle.jshell.net. This lets the user content do what it would normally do, but the browser’s cross-origin protection keeps the user content from messing with the host page or domain or cookies, etc….

    Trying to strip all possible places that scripts could be in the content is a risky proposition which you will probably forever be chasing new attack vectors. I’d personally much rather let the browser be in that business and put the user content on a different domain. Plus, allowing the user content to have it’s normal JS will also let it work as desired.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to display html code just like what your see here. <textarea><script id=ff>gdgdgs</script></textarea>
For the most part, when I want to display some HTML code to be
In My HTML Page I want to display certain Number of Buttons Based on
I want to Display news and events in a html page such that automatically
I want to display the ImageLink on my ASP.NET MVC Page. HTML. ImageLink is
I want to display strings like &amp; in an HTML page, but it is
I want to display HTML in a JEditorPane or JTextPane, but I want the
I want to display html in android activity through web view,my screen will be
I'm working on Ubuntu.(Linux) I want to display all .php pages to .html in
My HTML text is just like this: <p>abcdefghijklmnopqrstuvwxyz</p> What I want is to display

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.