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

hi,
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>
<BR>
<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

www.mydomain.com/myscript.html?input=%3Ca%20href%3D%22https%3A%2F%2Fwww.google.com%2Fsearch%3F%26q%3Dapples%22%3EClick%20for%20apples%3C%2Fa%3E%0A%3CBR%3E%0A%3Ca%20href%3D%22https%3A%2F%2Fwww.bing.com%2Fsearch%3F%26q%3Doranges%22%3EOr%20for%20oranges%3C%2Fa%3E%0A

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

Acknowledgement:
Encoding by https://meyerweb.com/eric/tools/dencoder/
xeniumAsked:
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 ChongCommented:
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.
0
David Johnson, CD, MVPOwnerCommented:
no you don't have to encode it. it works just as advertised.
http://ee2908660720180228074457.azurewebsites.net/
0
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.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy 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.

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

Open in new window

jQuery
<script>
$(function() {
  if (window.location.search.indexOf('=') > -1) {
    var search = decodeURIComponent(window.location.search.split('=')[1]);
	$('#target').html(search);
  }
});
</script>

Open in new window

0

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.
0
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.
0
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
HTML

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.