aboutsummaryrefslogtreecommitdiffstats
path: root/src/shared/generate-web-page.ts
blob: c3cc3a423a0269c1acf6af4a5e8f3e550901dc51 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/**
 * Opens a new browser tab and writes the given HTML content into it.
 * Used to display dynamically-generated pages (e.g. PDF-printable views).
 *
 * @param content - The full HTML string to write.
 * @param title   - The document title (default: `"Banglar Bhumi"`).
 */
export function generateWebPage(content: string, title: string = "Banglar Bhumi") {
	const tab = window.open("about:blank", "_blank");
	if (!tab) {
		return;
	}

	tab.addEventListener("DOMContentLoaded", () => {
		tab.document.body.innerHTML = content;
		tab.document.title = title;
		tab.document.close();
	});
	tab.focus();
};