On this page
- Key Takeaways
- Start with a fictional print URL
- Test three paths separately
- Find where the selection disappears
- Inspect the link and navigation
- Check routing and server logic
- Distinguish a fragment from a query parameter
- Build and read a deliberate print URL
- Consider privacy before putting selections in URLs
- Common Mistakes
- Best Practices
- Conclusion
A website print link not preserving a selected page can have several causes: the link may omit the selection, a redirect may remove it, or the print view may ignore it. The browser’s print dialog also has its own page-range controls, which are separate from an application’s selected content.
This guide walks through a fictional example and shows how to compare the URL, navigation, application state, and printed content. The example was not executed, and browser documentation was not available for this article; verify browser-specific print behavior against the documentation for your target browsers.
Key Takeaways
- First establish whether “page” means an item selected in the application or a physical page range in the browser’s print dialog.
- Compare the print link’s URL with the address after navigation, but also inspect the rendered content: matching URLs do not prove matching application state.
- A query parameter can be dropped by link generation, redirects, routing, or server code. A URL fragment is not sent in an HTTP request.
- Test direct navigation, the browser’s print command, and the site’s print control separately.
- Avoid putting sensitive selections in URLs unless the privacy consequences are acceptable.
Start with a fictional print URL
Suppose a document viewer uses page=3 to select content, and its print link points to:
https://example.test/documents/report/print?page=3
After following the link, suppose the address bar instead shows:
https://example.test/documents/report/print
The query parameter has disappeared from the displayed URL. That is a useful clue, but it does not establish where it was lost. The link might have been generated without it, the server might have redirected to a canonical URL, or client-side routing might have replaced the address. The application might also have read the parameter before removing it.
Before clicking, inspect or copy the link target. Then compare it with the address after navigation. If the two differ, use the browser’s developer tools to identify the transition; a text comparison alone cannot reveal the application’s internal state.
Also record what the print view actually renders. The application’s third page might be one section of a document, while the browser’s third printed sheet might be a different slice of the rendered document.
Advertisement
Test three paths separately
Use a document and selection you are authorized to inspect. For each test, record the browser and version, the starting URL, the selected application page, any resulting URL, the visible print content, and any browser print-dialog settings. Repeat in another supported browser if the result may be browser-specific.
| Test | Browser behavior to record | Application behavior to record |
|---|---|---|
| Direct navigation | Paste the full print URL into a new tab. Record the final address and any redirects. | Does the print view render the selected content? Does reloading change it? |
| Browser print | Open the viewer with the selection active, then use the browser’s print command. Record the preview and page-range settings. | Does the preview contain the selected content, the whole document, or different content? Does the site alter the document for printing? |
| Site print control | Activate the site’s print button or link. Record whether it navigates, opens a new tab, or opens a print dialog, plus any resulting address. | Does it carry the selected content into the print view or preview? |
A direct URL that works in a fresh tab suggests that the print route can reconstruct the selection from the URL. If it works only after navigating within the app, the print view may also depend on in-memory state, storage, or session state. If the site control fails while direct navigation works, inspect how that control builds its destination.
A browser print command does not necessarily exercise the site’s print route. It prints the current document; print-specific CSS or application print-event handlers can change what appears. The print dialog’s page range is not a substitute for passing the application’s content selection.
Find where the selection disappears
Inspect the link and navigation
Open developer tools and inspect the print control. For an ordinary link, check its href before activation. A button may instead run JavaScript that constructs a URL or calls the browser’s print function; inspect its handler or the resulting navigation.
In the Network panel, enable preservation of the request log before activating the control. Look for the initial document request, redirect responses and their Location headers, and the final document request. A server redirect can turn a request containing ?page=3 into a destination without it. Client-side navigation or a history update can also change the address, sometimes without a new document request.
Compare the network sequence with the address bar and the rendered print view. If the parameter survives the request but the wrong content appears, inspect the code that reads and validates the parameter and the server response that supplies the content.
Check routing and server logic
Common failure points include:
- A link builder creates the print path but forgets to add the selected page.
- A client-side router reconstructs the destination without copying the relevant query parameter.
- Server code redirects to a canonical print path without preserving an allowed parameter.
- The print view reads a different parameter name, rejects the value, or falls back to a default.
- The destination expects application state that is unavailable after a reload or in a new tab.
Preserve only parameters that the destination actually supports. The server and print view should validate the value and authorize access to the requested content; the presence of a query parameter is not proof of permission.
Distinguish a fragment from a query parameter
In https://example.test/documents/report/print#page=3, page=3 is a fragment, not a query parameter. The fragment is available to client-side code but is not sent as part of the HTTP request. A server-rendered print route therefore cannot read it directly from that request.
A client can interpret a fragment and explicitly send its value in a later request, but that is application behavior, not automatic HTTP behavior. If the server must choose content on the initial request, use an appropriate server-visible input, such as a validated query parameter, or redesign the flow so the client supplies the selection explicitly.
Advertisement
Build and read a deliberate print URL
The following illustrative browser-side function creates a print URL for an already-selected page. It assumes that /documents/report/print is a route in the same application and that its print view understands the page parameter. It has not been run here.
function makePrintUrl(selectedPage) {
if (!Number.isSafeInteger(selectedPage) || selectedPage < 1) {
throw new Error('Select a valid page before printing.');
}
const url = new URL('/documents/report/print', window.location.href);
url.searchParams.set('page', String(selectedPage));
return url.href;
}
// Example: use the application's actual selected-page state here.
const printLink = document.querySelector('#print-link');
if (!printLink) {
throw new Error('Print link not found.');
}
printLink.href = makePrintUrl(3);
This fixes only URL construction. The destination still needs to parse page, reject invalid or out-of-range values, check access to the document, and render the requested content. Decide explicitly what happens when the parameter is missing or invalid: show an error or use a documented default rather than silently printing the wrong selection.
After implementing a fix, repeat all three tests. Include a reload, a fresh tab, a missing parameter, an invalid value, and a selection the user is not authorized to access. Check the rendered content as well as the URL.
Consider privacy before putting selections in URLs
Query strings can appear in browser history, server and proxy logs, analytics, copied links, and potentially referrer information sent with subsequent requests, depending on configuration and policy. A fragment avoids being sent in the initial HTTP request, but it can still be visible in the address bar, copied, and read by page scripts. Encoding a value does not make it secret.
If the selection itself is sensitive, consider keeping it out of the URL and using an authenticated server-side workflow instead. Such a design must still enforce authorization, limit retention, and protect any identifier or stored state. Avoid placing credentials or sensitive document contents in either the query string or the fragment.
Common Mistakes
- Comparing only URL text. A matching address does not prove the print view used the parameter; a changed address does not prove the selection was lost.
- Testing only the browser print command. It may bypass the site’s dedicated print route entirely.
- Assuming fragments reach the server. They do not accompany the HTTP request unless client code explicitly transmits their contents.
- Confusing application pages with printed sheets. Record both the selected content and the browser dialog’s page-range setting.
- Preserving every query parameter blindly. Carry forward only parameters the print route needs and validates.
- Using a URL as an authorization mechanism. The print endpoint must independently check access to the requested document and selection.
Best Practices
Give the print view a clear contract: define the parameter name, valid range, missing-value behavior, and authorization requirements. Construct URLs with a URL API rather than string concatenation, and test both fresh navigation and in-app navigation. When diagnosing a failure, retain the redirect chain and record application content separately from browser print-dialog behavior.
Conclusion
Trace the selection from the source control to the print view, then test browser printing separately. The key is to find whether the value was omitted, removed during navigation, or retained but ignored—and to verify the printed content rather than relying on the address alone.
What would your domain sell for?
A free TidyURLs account unlocks the Domain Estimator. It prices a name from 191,011 real domain sales.