I made a very long line of html more readable using the backslash ‘\’ and breaking the url at the ampersand ‘&’ points.
The context is — displaying the Facebook Feed dialog box which takes several parameters, where each parameter is preceded by the ‘&’ character.
Here is the code:
<a class="fbShareToWall"
onClick='window.open("https://www.facebook.com/dialog/feed?app_id=10352809978xxxx \
&link=http://www.oursite.com \
&name=Our%20site \
&caption=For%20business \
&description=Good%20stuff \
&redirect_uri=http://www.oursite.com");'>Share on Facebook</a>
The url in the browser’s URL bar looks like this:
https://www.facebook.com/dialog/feed?app_id=10352809978xxxx &link=http://www.oursite.com
&name=Our site &caption=For business &description=Good stuff
&redirect_uri=http://www.oursite.com
There are big gaps between the ‘&’ parameters. Does it work? Sure. The browser must be filling in the big gaps with %20’s for each space. The above ‘gappy’ URL in the browser’s url bar successfully displays the Facebook ‘Feed’ dialog.
I need to make the code legible but take out the big gaps in the URL in the browser’s url bar.
Is there a way to do that and still wrap the very long ‘&’ parameter list onto separate lines with ‘\’ backslash?
Or is there anotherway to wrap a long html tag’s param list onto separate lines with no gaps in the browser URL bar?
Another way to wrap, since you’re in javascript:
I’m not sure what those backslashes are for in your code, but if they’re needed then you could probably include them: