1

P5 JavaScript was integrated with HTML and posted on GitHub. Normally, two parameters could be passed into the code by adding them to the HTML URL. This works when the code is tested locally. This fails when attempting to do this with the HTML page on github using syntax designed to preview the HTML page. Note that a straight up URL, by default, will display the source code rather than a working HTML page on a GitHub project. This is by design. The plan was to use this URL as the target of hyperlinks on the readme.md file. This would demonstrate the working code for visitors of the project.

The following things were tried after reviewing this StackOverflow post. These attempts did now work:

  1. https://rawgit.com/ ... (this downloads the file on clicking the link)
  2. Preview Syntax tried w/ parameters on the URL:
    1. http://htmlpreview.github.com/?https://github.com/TheMitchWorksPro/FlatIronLearningCode/blob/master/index.html?runModeToggle=1&runModeToggle2=1
    2. http://htmlpreview.github.com/?https://github.com/TheMitchWorksPro/FlatIronLearningCode/blob/master/index.html&runModeToggle=1&runModeToggle2=1
    3. Escape second ? in option 1 as in ...\?runModeToggle=1&run...
    4. Put whole URL after first ? in quotes as in http://htmlpreview.github.com/?"https://github.com/ ... "

My code is presented for learning purposes showing how it evolved. Earlier iterations that did simpler things without the parameters display fine. For example:

http://htmlpreview.github.com/?https://github.com/TheMitchWorksPro/FlatIronLearningCode/blob/master/original/index.html

But for the one flavor of the code that needs parameters to work, this is where the trouble is. This post also suggests other things to try but none of them solves the problem. If this URL worked properly, then both parameters would show up as their corresponding numbers in the second line of text on the page, and they would cause certain behaviors when a user clicks (mousepressed) on the page:

http://htmlpreview.github.com/?https://github.com/TheMitchWorksPro/FlatIronLearningCode/blob/master/index.html?runModeToggle=1&runModeToggle2=1

undercovertek
  • 148
  • 1
  • 11
TMWP
  • 1,545
  • 1
  • 17
  • 31
  • Sorry, I'm really not sure what you're asking. Can you please post a small sample of code that shows what you're trying? Please try to be more specific. What exactly do you mean when you say "it didn't work" when you escaped the `?` characters? – Kevin Workman Mar 20 '18 at 16:14
  • posting an answer to this problem. I found one. Hopefully question and answer together will make a bit more sense. – TMWP Mar 20 '18 at 16:33
  • I tried to see if I could make your question clearer for K. Workman. See if this edit is better. – undercovertek Mar 20 '18 at 17:03
  • Thanks. Just approved. – TMWP Mar 20 '18 at 17:08

1 Answers1

1

Not mentioned in the original write-up, the code being tested outputs the URL parameters at the top of the page for demonstration purposes as well as using them within the code. When testing this URL from the question:

http://htmlpreview.github.io/?https://github.com/TheMitchWorksPro/FlatIronLearningCode/blob/master/index.html?runModeToggle=1&runModeToggle2=1

Note how the second line shows that the first argument is "undefined" while the other argument is showing up as a "1". I was able to fix the problem by simply adding a dummy argument ahead of the real one. Why this would be the case is currently unknown, but it seems to solve the problem:

http://htmlpreview.github.io/?https://github.com/TheMitchWorksPro/FlatIronLearningCode/blob/master/index.html?arg1=0&runModeToggle=1&runModeToggle2=1

To see the code working in action with all flavors of the arguments, modified URLs have now been added to the Readme file on the main page of this project:

https://github.com/TheMitchWorksPro/FlatIronLearningCode

undercovertek
  • 148
  • 1
  • 11
TMWP
  • 1,545
  • 1
  • 17
  • 31