I'd like to load a stylesheet when my URL variable contains "?view=full".
Is it possible to do this in HTML (i.e. not PHP)? If so, how?
I'd like to load a stylesheet when my URL variable contains "?view=full".
Is it possible to do this in HTML (i.e. not PHP)? If so, how?
It’s not possible in pure HTML; you'd have to use either PHP or JavaScript. If you want to do it in JavaScript, you could put this in your <head>
section:
<script>
if (window.location.search.indexOf('?view=full') === 0)
document.write('<link rel="stylesheet" href="theStylesheet.css" />');
</script>
<script>
tag, not any other tag. –
Primordial <?php if (isset($_GET['view']) && $_GET['view'] === 'full') { ?><link rel="stylesheet" href="theStylesheet.css" /><?php } ?>
or something. isset
might not be necessary, it’s been a while since I’ve written PHP. –
Primordial This will create the link
element in your head
element if that GET param is present.
if (window.location.search.search(/[?&]view=full(?:$|&)/) !== -1) {
var link = document.createElement('link');
link.type = 'text/css';
link.rel = 'stylesheet';
link.href = 'path/to/it.css';
document.getElementsByTagName('head')[0].appendChild(link);
}
<link>
element. <style>
elements do not have an href
attribute, nor a rel
attribute. –
Primordial © 2022 - 2024 — McMap. All rights reserved.