Displaying a simple HTML page from input embedded into a URL (part IV)

I'm looking to display very simple web pages from HTML contained within a URL, for example:

To display a webpage comprising the following HTML...

<a href="https://www.google.com/search?&q=apples">Click for apples</a>
<a href="https://www.bing.com/search?&q=oranges">Or for oranges</a>

Open in new window

...the HTML would be included in a URL that points to a script that will display it, eg


Open in new window

I'm not sure if the encoding is necessary, ideally if not i would avoid it in which case the URL would be:

www.mydomain.com/myscript.html?input=<a href="https://www.google.com/search?&q=apples">Click for apples</a><BR><a href="https://www.bing.com/search?&q=oranges">Or for oranges</a>

Open in new window

I need the script for myscript.html

This is a generic version of this question: https://www.experts-exchange.com/questions/29086043/Displaying-a-simple-HTML-page-from-input-embedded-into-a-URL.html

Many thanks

Encoding by https://meyerweb.com/eric/tools/dencoder/
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan ChongSoftware Team Lead, ex-Business Systems Analyst , ex-Senior Application EngineerCommented:
to put as URL (query string) with HTML codes, you wil need to encode the content.

or else try to accept by adapting post data instead.

but no matter what, it would be better to verify what was being passed to your script before you process and display it, for security purposes.
David Johnson, CD, MVPOwnerCommented:
no you don't have to encode it. it works just as advertised.
Julian HansenCommented:
The encoding is not necessary it was originally suggested due to the fact that characters that are valid in URL's were being used and it was a way to ensure that delimiting characters were not misinterpreted.

With the delimiters chosen you should be fine using the non encoded version.
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

xeniumAuthor Commented:
hi Julian,

Thanks again.

The script i need in this question is probably simpler than the ones before. In this general case the HTML is created before submitting it to the URL (rather than have the javascript create it) so then the javascript simply displays the HTML. This HTML could be anything (within any length limits imposed by the browser) and could for example just display a note with a picture for example.

It's probably a trivial operation in javascript, but my knowledge here is zero!

Thanks again for your help.

Julian HansenCommented:
In that case you should encode it - the javascript then just display it
<div id="target"></div>

Open in new window

$(function() {
  if (window.location.search.indexOf('=') > -1) {
    var search = decodeURIComponent(window.location.search.split('=')[1]);

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
xeniumAuthor Commented:
Thanks again that works fine.
xeniumAuthor Commented:
Only on bluehost do i get the following error, any ideas?

Not Acceptable!
An appropriate representation of the requested resource could not be found on this server. This error was generated by Mod_Security.

Update: a quick google suggests i need to update my htaccess file.

Here is a separate question on the issue.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.