How to print get method in javascript - printing

I want to print mod value in javascript document.write
for example my url is http://sitename.com/test.js?mod=57
now I want print 57 in document.write
document.write('<img src="http://utools.com/tools/mousse/mousse'+mod+'.png" />');

Related

Thymeleaf check if the URL contains a parameter

I'm trying to run a JS script if my URL contains a certain parameter. I'm doing this with
<script th:inline="javascript" th:if="${param.param3} != null"> ... </script>
My full URL looks something like this URI?param1=...&param2=..?param3=...
I'm trying to get param3 - and it works if I use a & before it instead of a ? but I want to get it if it has a ? before it...how can I do it?

Vaadin 23 preformatted text output

In Vaadin 8 there is the possibility to show preformatted text with help of the Label component -
Label preLabel = new Label(
"Preformatted text is shown in an HTML <pre> tag.\n" +
"Formatting such as\n" +
" * newlines\n" +
" * whitespace\n" +
"and such are preserved. HTML tags, \n"+
"such as <b>bold</b>, are quoted.",
ContentMode.PREFORMATTED);
https://vaadin.com/docs/v8/framework/components/components-label
How to achieve the same with Vaadin 23 ? I need to pretty print text on the page which contains line breaks \n
The Html class in Flow is intended for freeform HTML content: https://vaadin.com/api/platform/23.1.4/com/vaadin/flow/component/Html.html
Note that the content given to it must be enclosed in a top-level html element, e.g. "<span>Preformatted<b>stuff</b></span>" is ok, while "Preformatted <b>stuff</b>" is not.
If you only need line breaks, however, you could also try the Pre class which renders as a element https://vaadin.com/api/platform/23.1.4/com/vaadin/flow/component/html/Pre.html
E.g. Pre pre = new Pre("This text has line\nbreaks");

SAS proc stream : weird linebreaks

Server: Unix, Client: IE Edge
Part of my code:
%let P_debug_log = %str(<INPUT TYPE='hidden' NAME='_DEBUG' VALUE='LOG'>);
proc stream outfile=_webout quoting=both resetdelim='_do' ASIS;
BEGIN
%if "&_whattodo" ne "print" %then %do;
<script language='JavaScript' type='text/javascript'>
function subForm(f,v) {
if (v !== '') {
$('#'+ f).append('<INPUT TYPE="hidden" NAME="'+ v +'" VALUE="1">');
}
$('#'+f).submit();
}
$(document).ready(function() {
$('#footButtons').append($('.footButton')); /* move all elements with class=footButton to pageFooter */
$('#footMessage').append($('.footMsg'));
$('form.log').append("&P_debug_log.");
});
</script>
%end;
;;;;
Output:
The Problem is, that generated stream Output has linebreaks "somewhere" but not where expected (with Option ASIS it should be formatted like in my code).
This leads to unpredictable JavaScript Errors, e.g. when a linebreak is within a JavaScript string.
It seems as if there is an implicit LRECL 1024. This would be OK if linebreaks would be set as expected.
Any hints?
This is the originally formatted Output (Page Source):
<script language='JavaScript' type='text/javascript'> function subForm(f,v) { if (v !== '') { $('#'+ f).append('<INPUT TYPE="hidden" NAME="'+ v +'" VALUE="1">'); } $('#'+f).submit(); }
$(document).ready(function() { $('#footButtons').append($('.footButton')); $('#footMessage').append($('.footMsg')); $('form.log').append("
<INPUT TYPE=
'hidden
' NAME=
'_DEBUG
' VALUE=
'LOG
'
>"); }); </script>
Not sure if I have an answer, but it looks like the macro quoting is what is causing PROC STREAM to separate out the macro variable into multiple lines.
So if I run this simplified example:
%let P_debug_log = %str(<INPUT TYPE='hidden' NAME='_DEBUG' VALUE='LOG'>);
filename tst temp;
proc stream outfile=tst quoting=both resetdelim='_do' ASIS;
BEGIN
$('form.log').append("&P_debug_log.");
;;;;
Then it generates this file:
$('form.log').append("
<INPUT TYPE='hidden
' NAME='_DEBUG
' VALUE='LOG
'>");
If you remove the %STR() from around the value of the macro variable then it only inserts line breaks before and after the full macro variable reference and not also around the quotes in the macro variable.
$('form.log').append("
<INPUT TYPE='hidden' NAME='_DEBUG' VALUE='LOG'>
");
If you remove the quoting=both option then the line breaks will be outside the quotes, whether or not you use macro quoting.
$('form.log').append(
"<INPUT TYPE='hidden' NAME='_DEBUG' VALUE='LOG'>"
);
First of all, thank you all for your answers.
Robert Penridge was right.
Solution:
If you use PROC STREAM and want to include static code (as in my case: Javascript), then use &STREAMDELIM READFILE instead of %include.
Reason: if there are (valid!) inline comments "//" (comment until next linebreak,) in the included code, it will lead to unpredictable results....
thanks a lot,
dbdb
Simply remove the ASIS option you have added to proc stream.
I'm not sure if this is an undocumented feature but it doesn't appear in the documentation so I'm assuming so.
http://documentation.sas.com/?docsetId=proc&docsetVersion=9.4&docsetTarget=n12zrkr08eiacmn17lcv4fmt79tb.htm&locale=en
Once you remove that the weird line breaks disappear.
Searching around, it appears the ASIS option is something to do with attempting to preserve column alignment.

How do I insert field values from database into an HTML table using Delphi?

I'm generating a HTML order confirmation email using the TIdMessage Indy component in Delphi XE6.
I can add a line to my TIdMessage using:
IdMessage1.Body.Text := '<P STYLE="margin-bottom: 0.2in"><FONT COLOR="#FF0000"><FONT FACE="Calibri"><B> Order Confirmation for Work Order # ' + MyDatasetNameWorkOrder.AsString + '</B></FONT></FONT></P><P STYLE="margin-bottom: 0.2in"><FONT FACE="Calibri">Hello ' + OrdersForm.Proper(ServiceContact1DBText.Field.AsString) + ',</FONT></FONT></P>';`
and then add my HTML head/body sections after those lines, and the resulting email works. It displays the proper Work Order # and Contact when displayed as a HTML email.
But if I add the code above to the body section of my HTML email it doesn't show the table value for the Work Order #, or the Contact person. It just shows the actual text like + MyDatasetNameWorkOrder.AsString + and + OrdersForm.Proper(ServiceContact1DBText.Field.AsString) + in that area of the email.
Do I have to wrap those lines with some other code when trying to embed or insert a database value in a HTML paragraph or table?

Output Image URL in JSF XHTML containing '&' [duplicate]

I want to put a packman game on my *.xhtml page.(I am using jsf 2 and primefaces 3.5)
However,
when I "translated" the html page in xhtml I get an error at this script:
<script>
var el = document.getElementById("pacman");
if (Modernizr.canvas && Modernizr.localstorage &&
Modernizr.audio && (Modernizr.audio.ogg || Modernizr.audio.mp3)) {
window.setTimeout(function () { PACMAN.init(el, "./"); }, 0);
} else {
el.innerHTML = "Sorry, needs a decent browser<br /><small>" +
"(firefox 3.6+, Chrome 4+, Opera 10+ and Safari 4+)</small>";
}
</script>
At line:
if (Modernizr.canvas && Modernizr.localstorage &&
i get:
The entity name must immediately follow the '&' in the entity
reference.
Any idea how to fix that?
All answers posted so far are giving the right solutions, however no one answer was able to properly explain the underlying cause of the concrete problem.
Facelets is a XML based view technology which uses XHTML+XML to generate HTML output. XML has five special characters which has special treatment by the XML parser:
< the start of a tag.
> the end of a tag.
" the start and end of an attribute value.
' the alternative start and end of an attribute value.
& the start of an entity (which ends with ;).
In case of & which is not followed by # (e.g.  ,  , etc), the XML parser is implicitly looking for one of the five predefined entity names lt, gt, amp, quot and apos, or any manually defined entity name. However, in your particular case, you was using & as a JavaScript operator, not as an XML entity. This totally explains the XML parsing error you got:
The entity name must immediately follow the '&' in the entity reference
In essence, you're writing JavaScript code in the wrong place, a XML document instead of a JS file, so you should be escaping all XML special characters accordingly. The & must be escaped as &.
So, in your particular case, the
if (Modernizr.canvas && Modernizr.localstorage &&
must become
if (Modernizr.canvas && Modernizr.localstorage &&
to make it XML-valid.
However, this makes the JavaScript code harder to read and maintain. In case when you want to continue using & instead of & in JavaScript code in a XML document, then you should be placing the JavaScript code in a character data (CDATA) block. Thus, in JSF terms, that would be:
<h:outputScript>
<![CDATA[
// ...
]]>
</h:outputScript>
The XML parser will interpret the block's contents as "plain vanilla" character data and not as XML and hence interpret the XML special characters "as-is".
But, much better is to just put the JS code in its own JS file which you include by <script src>, or in JSF terms, the <h:outputScript>.
<h:outputScript name="onload.js" target="body" />
(note the target="body"; this way JSF will automatically render the <script> at the very end of <body>, regardless of where <h:outputScript> itself is located, hereby achieving the same effect as with window.onload and $(document).ready(); so you don't need to use those anymore in that script)
This way you don't need to worry about XML-special characters in your JS code. As an additional bonus, this gives you the opportunity to let the browser cache the JS file so that total response size is smaller.
See also:
Error Parsing /page.xhtml: Error Traced[line: 42] The entity "nbsp" was referenced, but not declared
Is it possible to use JSF+Facelets with HTML 4/5?
How to reference CSS / JS / image resource in Facelets template?
You need to add a CDATA tag inside of the script tag, unless you want to manually go through and escape all XHTML characters (e.g. & would need to become &). For example:
<script>
//<![CDATA[
var el = document.getElementById("pacman");
if (Modernizr.canvas && Modernizr.localstorage &&
Modernizr.audio && (Modernizr.audio.ogg || Modernizr.audio.mp3)) {
window.setTimeout(function () { PACMAN.init(el, "./"); }, 0);
} else {
el.innerHTML = "Sorry, needs a decent browser<br /><small>" +
"(firefox 3.6+, Chrome 4+, Opera 10+ and Safari 4+)</small>";
}
//]]>
</script>
The parser is expecting some HTML content, so it sees & as the beginning of an entity, like è.
Use this workaround:
<script type="text/javascript">
// <![CDATA[
Javascript code here
// ]]>
</script>
so you specify that the code is not HTML text but just data to be used as is.
Do
<script>//<![CDATA[
/* script */
//]]></script>
If you use XHTML, for some reason, note that XHTML 1.0 C 4 says: “Use external scripts if your script uses < or & or ]]> or --.” That is, don’t embed script code inside a script element but put it into a separate JavaScript file and refer to it with <script src="foo.js"></script>.
Just in case someone from Blogger arrives, I had this problem when using Beautify extension in VSCode. Don´t use it, don´t beautify it.

Resources