Web Connection
Live Reload script problem - WC 8.1
Gravatar is a globally recognized avatar based on your email address. Live Reload script problem - WC 8.1
  Marcel DESMET
  All
  Feb 14, 2025 @ 03:06am

Hello,

Just wanted to test quickly and put my script is beteween div elements, here is the result You merge your reload script before the end my script Html ( with script ) is generated with a Helper before it is merge in a template

<script>
function customPrint() {
	var printContents = document.querySelector('.printable-content').innerHTML;
	var originalContents = document.body.innerHTML;

	var printWindow = window.open('', '', 'height=600,width=800');
	printWindow.document.write('<html><head><title>Print</title>');
	printWindow.document.write('<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.1.3/css/bootstrap.min.css">');
	printWindow.document.write('<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-icons/1.8.1/font/bootstrap-icons.min.css">');
	printWindow.document.write('<style>body { margin: 20px; }</style>');
	printWindow.document.write('</head><body>');
	printWindow.document.write(printContents);
	printWindow.document.write('
<!-- West Wind Live Reload -->
<script>
(function(retryTimeout) {

setTimeout(function () {

Tks Marcel

Gravatar is a globally recognized avatar based on your email address. re: Live Reload script problem - WC 8.1
  Marcel DESMET
  Marcel DESMET
  Feb 14, 2025 @ 03:09am

The problem is

printWindow.document.write('</body></html>');

You put your script before < / b o d y >

Gravatar is a globally recognized avatar based on your email address. re: Live Reload script problem - WC 8.1
  Rick Strahl
  Marcel DESMET
  Feb 14, 2025 @ 09:50am

Whut?

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Live Reload script problem - WC 8.1
  Marcel DESMET
  Rick Strahl
  Feb 14, 2025 @ 09:33pm

When you add your reload script on the 'respons' you position it before the end tag of the body

Only I use this end tag in my print script, which poses a problem.

The reason is obvious in the code above

Gravatar is a globally recognized avatar based on your email address. re: Live Reload script problem - WC 8.1
  Rick Strahl
  Marcel DESMET
  Feb 15, 2025 @ 11:22am

Oh I see what you mean. Change the end tag in your script to </ body> and it should work.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Live Reload script problem - WC 8.1
  Rick Strahl
  Marcel DESMET
  Feb 15, 2025 @ 11:44am

I've added some logic to only replace the last </body> tag so this should cut down on potential issues like this by quite bit.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Live Reload script problem - WC 8.1
  Marcel DESMET
  Rick Strahl
  Feb 16, 2025 @ 10:50am

Thank you !

Marcel

Gravatar is a globally recognized avatar based on your email address. re: Live Reload script problem - WC 8.1
  Richard Kaye
  Rick Strahl
  Feb 18, 2025 @ 05:22am

I wonder if this is the root cause for the various issues I've had with using LiveReload in my dev as we also are a bit of a hybrid in terms of how we generate pages. Is this available in the usual experimental place?

Gravatar is a globally recognized avatar based on your email address. re: Live Reload script problem - WC 8.1
  Rick Strahl
  Richard Kaye
  Feb 18, 2025 @ 01:45pm

Yes... in the usual place.

I think this is an edge case where a </body> tag was explicitly generated in Javascript code. That's a pretty unlikely scenario to happen as it implies your loading HTML into another frame or for display.

IAC, the fix of just converting the last tag should be pretty safe unless you're really going nuts and write code outside of the body tag altogether.

This is the problem with templates and templating in general - there are always those edge cases where the content you're looking for in parsing is also embedded in some internal content of the page. Hard to think of all the cases, but it can be a pain.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Live Reload script problem - WC 8.1
  Richard Kaye
  Rick Strahl
  Feb 19, 2025 @ 06:58am

Only rigid adherence to the template model can prevent forest fires... Or something like that. 😉

Gravatar is a globally recognized avatar based on your email address. re: Live Reload script problem - WC 8.1
  Rick Strahl
  Richard Kaye
  Feb 19, 2025 @ 09:14am

... it's good to be the King!

All you bloody rebels trying to skirt the rules... 😄

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Live Reload script problem - WC 8.1
  Richard Kaye
  Rick Strahl
  Feb 20, 2025 @ 04:32am

Long live the King!

© 1996-2025