Dynamically load external css resources model sideLoad and execution sequence of a web page?HTML5 appcache with Safari causing cross site css not to loadUse Adobe TypeKit fonts in an SVG object embedded in an HTML pagehow to use google font in less css ? any other solution to embedded custom font in less?Loading Google font in HTTPS, content being blockedImporting a google font on freecodecamp.comiphone mail won't load google font OswaldAMP page reference for external cssFonts not displayed on HTML email and underline comes for hyperlinksIs there a way to perfectly consider both Page Speed Optimization and customized Google Fonts?
Why would company (decision makers) wait for someone to retire, rather than lay them off, when their role is no longer needed?
Is there any good reason to write "it is easy to see"?
Why did the UK remove the 'European Union' from its passport?
2 parabolas through 4 points
Why when I add jam to my tea it stops producing thin "membrane" on top?
Single word that parallels "Recent" when discussing the near future
What information exactly does an instruction cache store?
the correct order of manual install WP and SSL on server
With today's technology, could iron be smelted at La Rinconada?
labelled end points on logic diagram
Wireless headphones interfere with Wi-Fi signal on laptop
Does the Rogue's Reliable Talent feature work for thieves' tools, since the rogue is proficient in them?
How does Ctrl+c and Ctrl+v work?
c++ conditional uni-directional iterator
Polynomial division: Is this trick obvious?
How to continually let my readers know what time it is in my story, in an organic way?
What dog breeds survive the apocalypse for generations?
Why is the Advance Variation considered strong vs the Caro-Kann but not vs the Scandinavian?
Why commonly or frequently used fonts sizes are even numbers like 10px, 12px, 16px, 24px, or 32px?
Why do galaxies collide
What color to choose as "danger" if the main color of my app is red
Is the seat-belt sign activation when a pilot goes to the lavatory standard procedure?
How to rename multiple files in a directory at the same time
Which creature is depicted in this Xanathar's Guide illustration of a war mage?
Dynamically load external css resources model side
Load and execution sequence of a web page?HTML5 appcache with Safari causing cross site css not to loadUse Adobe TypeKit fonts in an SVG object embedded in an HTML pagehow to use google font in less css ? any other solution to embedded custom font in less?Loading Google font in HTTPS, content being blockedImporting a google font on freecodecamp.comiphone mail won't load google font OswaldAMP page reference for external cssFonts not displayed on HTML email and underline comes for hyperlinksIs there a way to perfectly consider both Page Speed Optimization and customized Google Fonts?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I need to dynamically load external css resource to change font family of the page.
In my SPA the user chooses the font family he prefers for the UI. So he copy/paste the font family from https://fonts.google.com into an input tag and I need to change accordingly the page font-family property.
In order to do this, I need to load the external resource of the font such as <link href="https://fonts.googleapis.com/css?family=<FONTFAMILYNAME>" rel="stylesheet">
and then change the css assigning font-family: 'Indie Flower', cursive;
to the page, that is not a problem using css binding.
How can I do this from the model side?
UPDATE
The app is developed with Aurelia js framework, so I mean the Aurelia model, but (still in client-side)
css aurelia
add a comment |
I need to dynamically load external css resource to change font family of the page.
In my SPA the user chooses the font family he prefers for the UI. So he copy/paste the font family from https://fonts.google.com into an input tag and I need to change accordingly the page font-family property.
In order to do this, I need to load the external resource of the font such as <link href="https://fonts.googleapis.com/css?family=<FONTFAMILYNAME>" rel="stylesheet">
and then change the css assigning font-family: 'Indie Flower', cursive;
to the page, that is not a problem using css binding.
How can I do this from the model side?
UPDATE
The app is developed with Aurelia js framework, so I mean the Aurelia model, but (still in client-side)
css aurelia
1
It's not clear what you mean by "model side". Are you talking about doing this from a server instead of the client? Your question is kinda unclear.
– Geo1088
Mar 23 at 15:21
@Geo1088 I updated the question, it should be clearer now.
– jafed
Mar 23 at 18:10
add a comment |
I need to dynamically load external css resource to change font family of the page.
In my SPA the user chooses the font family he prefers for the UI. So he copy/paste the font family from https://fonts.google.com into an input tag and I need to change accordingly the page font-family property.
In order to do this, I need to load the external resource of the font such as <link href="https://fonts.googleapis.com/css?family=<FONTFAMILYNAME>" rel="stylesheet">
and then change the css assigning font-family: 'Indie Flower', cursive;
to the page, that is not a problem using css binding.
How can I do this from the model side?
UPDATE
The app is developed with Aurelia js framework, so I mean the Aurelia model, but (still in client-side)
css aurelia
I need to dynamically load external css resource to change font family of the page.
In my SPA the user chooses the font family he prefers for the UI. So he copy/paste the font family from https://fonts.google.com into an input tag and I need to change accordingly the page font-family property.
In order to do this, I need to load the external resource of the font such as <link href="https://fonts.googleapis.com/css?family=<FONTFAMILYNAME>" rel="stylesheet">
and then change the css assigning font-family: 'Indie Flower', cursive;
to the page, that is not a problem using css binding.
How can I do this from the model side?
UPDATE
The app is developed with Aurelia js framework, so I mean the Aurelia model, but (still in client-side)
css aurelia
css aurelia
edited May 4 at 15:36
Cœur
19.9k10117158
19.9k10117158
asked Mar 23 at 15:15
jafedjafed
12811
12811
1
It's not clear what you mean by "model side". Are you talking about doing this from a server instead of the client? Your question is kinda unclear.
– Geo1088
Mar 23 at 15:21
@Geo1088 I updated the question, it should be clearer now.
– jafed
Mar 23 at 18:10
add a comment |
1
It's not clear what you mean by "model side". Are you talking about doing this from a server instead of the client? Your question is kinda unclear.
– Geo1088
Mar 23 at 15:21
@Geo1088 I updated the question, it should be clearer now.
– jafed
Mar 23 at 18:10
1
1
It's not clear what you mean by "model side". Are you talking about doing this from a server instead of the client? Your question is kinda unclear.
– Geo1088
Mar 23 at 15:21
It's not clear what you mean by "model side". Are you talking about doing this from a server instead of the client? Your question is kinda unclear.
– Geo1088
Mar 23 at 15:21
@Geo1088 I updated the question, it should be clearer now.
– jafed
Mar 23 at 18:10
@Geo1088 I updated the question, it should be clearer now.
– jafed
Mar 23 at 18:10
add a comment |
1 Answer
1
active
oldest
votes
Hope It is what you expected
let btn = document.getElementById("btn");
let inpt = document.getElementById("inpt");
let fontsLink = document.getElementById("fontsLink");
btn.addEventListener('click', function()
let font = inpt.value;
font = font.trim();
font = font.replace(/ /g, '+');
let link = `
https://fonts.googleapis.com/css?family=$font
`
fontsLink.href = link;
document.querySelector('body').style.fontFamily = `$inpt.value`;
);
*
box-sizing: border-box;
font-family: inherit;
html
font-size: 62.25%;
body
font-family: sans-serif;
font-size: 1.6rem;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Hello World From Gaurav</title>
<link rel="stylesheet" href="" id="fontsLink">
</head>
<body>
<h1 id="demo" contenteditable="true">Change Text</h1>
<input id="inpt" type="" placeholder="Type Font Name">
<button id="btn">Load</button>
</body>
</html>
It's a really good hint but it isn't using the Aurelia framework. Thanks by the way.
– jafed
Mar 23 at 18:11
1
The solution actually works like a charm and it needs only some consideration to be used with Aurelia application like adding a fake link tag (called fontsLink in the answer) into the index.ejs file. it's not the best because of this. thanks @guarav
– jafed
Mar 23 at 18:56
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55315197%2fdynamically-load-external-css-resources-model-side%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Hope It is what you expected
let btn = document.getElementById("btn");
let inpt = document.getElementById("inpt");
let fontsLink = document.getElementById("fontsLink");
btn.addEventListener('click', function()
let font = inpt.value;
font = font.trim();
font = font.replace(/ /g, '+');
let link = `
https://fonts.googleapis.com/css?family=$font
`
fontsLink.href = link;
document.querySelector('body').style.fontFamily = `$inpt.value`;
);
*
box-sizing: border-box;
font-family: inherit;
html
font-size: 62.25%;
body
font-family: sans-serif;
font-size: 1.6rem;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Hello World From Gaurav</title>
<link rel="stylesheet" href="" id="fontsLink">
</head>
<body>
<h1 id="demo" contenteditable="true">Change Text</h1>
<input id="inpt" type="" placeholder="Type Font Name">
<button id="btn">Load</button>
</body>
</html>
It's a really good hint but it isn't using the Aurelia framework. Thanks by the way.
– jafed
Mar 23 at 18:11
1
The solution actually works like a charm and it needs only some consideration to be used with Aurelia application like adding a fake link tag (called fontsLink in the answer) into the index.ejs file. it's not the best because of this. thanks @guarav
– jafed
Mar 23 at 18:56
add a comment |
Hope It is what you expected
let btn = document.getElementById("btn");
let inpt = document.getElementById("inpt");
let fontsLink = document.getElementById("fontsLink");
btn.addEventListener('click', function()
let font = inpt.value;
font = font.trim();
font = font.replace(/ /g, '+');
let link = `
https://fonts.googleapis.com/css?family=$font
`
fontsLink.href = link;
document.querySelector('body').style.fontFamily = `$inpt.value`;
);
*
box-sizing: border-box;
font-family: inherit;
html
font-size: 62.25%;
body
font-family: sans-serif;
font-size: 1.6rem;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Hello World From Gaurav</title>
<link rel="stylesheet" href="" id="fontsLink">
</head>
<body>
<h1 id="demo" contenteditable="true">Change Text</h1>
<input id="inpt" type="" placeholder="Type Font Name">
<button id="btn">Load</button>
</body>
</html>
It's a really good hint but it isn't using the Aurelia framework. Thanks by the way.
– jafed
Mar 23 at 18:11
1
The solution actually works like a charm and it needs only some consideration to be used with Aurelia application like adding a fake link tag (called fontsLink in the answer) into the index.ejs file. it's not the best because of this. thanks @guarav
– jafed
Mar 23 at 18:56
add a comment |
Hope It is what you expected
let btn = document.getElementById("btn");
let inpt = document.getElementById("inpt");
let fontsLink = document.getElementById("fontsLink");
btn.addEventListener('click', function()
let font = inpt.value;
font = font.trim();
font = font.replace(/ /g, '+');
let link = `
https://fonts.googleapis.com/css?family=$font
`
fontsLink.href = link;
document.querySelector('body').style.fontFamily = `$inpt.value`;
);
*
box-sizing: border-box;
font-family: inherit;
html
font-size: 62.25%;
body
font-family: sans-serif;
font-size: 1.6rem;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Hello World From Gaurav</title>
<link rel="stylesheet" href="" id="fontsLink">
</head>
<body>
<h1 id="demo" contenteditable="true">Change Text</h1>
<input id="inpt" type="" placeholder="Type Font Name">
<button id="btn">Load</button>
</body>
</html>
Hope It is what you expected
let btn = document.getElementById("btn");
let inpt = document.getElementById("inpt");
let fontsLink = document.getElementById("fontsLink");
btn.addEventListener('click', function()
let font = inpt.value;
font = font.trim();
font = font.replace(/ /g, '+');
let link = `
https://fonts.googleapis.com/css?family=$font
`
fontsLink.href = link;
document.querySelector('body').style.fontFamily = `$inpt.value`;
);
*
box-sizing: border-box;
font-family: inherit;
html
font-size: 62.25%;
body
font-family: sans-serif;
font-size: 1.6rem;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Hello World From Gaurav</title>
<link rel="stylesheet" href="" id="fontsLink">
</head>
<body>
<h1 id="demo" contenteditable="true">Change Text</h1>
<input id="inpt" type="" placeholder="Type Font Name">
<button id="btn">Load</button>
</body>
</html>
let btn = document.getElementById("btn");
let inpt = document.getElementById("inpt");
let fontsLink = document.getElementById("fontsLink");
btn.addEventListener('click', function()
let font = inpt.value;
font = font.trim();
font = font.replace(/ /g, '+');
let link = `
https://fonts.googleapis.com/css?family=$font
`
fontsLink.href = link;
document.querySelector('body').style.fontFamily = `$inpt.value`;
);
*
box-sizing: border-box;
font-family: inherit;
html
font-size: 62.25%;
body
font-family: sans-serif;
font-size: 1.6rem;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Hello World From Gaurav</title>
<link rel="stylesheet" href="" id="fontsLink">
</head>
<body>
<h1 id="demo" contenteditable="true">Change Text</h1>
<input id="inpt" type="" placeholder="Type Font Name">
<button id="btn">Load</button>
</body>
</html>
let btn = document.getElementById("btn");
let inpt = document.getElementById("inpt");
let fontsLink = document.getElementById("fontsLink");
btn.addEventListener('click', function()
let font = inpt.value;
font = font.trim();
font = font.replace(/ /g, '+');
let link = `
https://fonts.googleapis.com/css?family=$font
`
fontsLink.href = link;
document.querySelector('body').style.fontFamily = `$inpt.value`;
);
*
box-sizing: border-box;
font-family: inherit;
html
font-size: 62.25%;
body
font-family: sans-serif;
font-size: 1.6rem;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Hello World From Gaurav</title>
<link rel="stylesheet" href="" id="fontsLink">
</head>
<body>
<h1 id="demo" contenteditable="true">Change Text</h1>
<input id="inpt" type="" placeholder="Type Font Name">
<button id="btn">Load</button>
</body>
</html>
answered Mar 23 at 16:35
Gaurav BhardwajGaurav Bhardwaj
2217
2217
It's a really good hint but it isn't using the Aurelia framework. Thanks by the way.
– jafed
Mar 23 at 18:11
1
The solution actually works like a charm and it needs only some consideration to be used with Aurelia application like adding a fake link tag (called fontsLink in the answer) into the index.ejs file. it's not the best because of this. thanks @guarav
– jafed
Mar 23 at 18:56
add a comment |
It's a really good hint but it isn't using the Aurelia framework. Thanks by the way.
– jafed
Mar 23 at 18:11
1
The solution actually works like a charm and it needs only some consideration to be used with Aurelia application like adding a fake link tag (called fontsLink in the answer) into the index.ejs file. it's not the best because of this. thanks @guarav
– jafed
Mar 23 at 18:56
It's a really good hint but it isn't using the Aurelia framework. Thanks by the way.
– jafed
Mar 23 at 18:11
It's a really good hint but it isn't using the Aurelia framework. Thanks by the way.
– jafed
Mar 23 at 18:11
1
1
The solution actually works like a charm and it needs only some consideration to be used with Aurelia application like adding a fake link tag (called fontsLink in the answer) into the index.ejs file. it's not the best because of this. thanks @guarav
– jafed
Mar 23 at 18:56
The solution actually works like a charm and it needs only some consideration to be used with Aurelia application like adding a fake link tag (called fontsLink in the answer) into the index.ejs file. it's not the best because of this. thanks @guarav
– jafed
Mar 23 at 18:56
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55315197%2fdynamically-load-external-css-resources-model-side%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
It's not clear what you mean by "model side". Are you talking about doing this from a server instead of the client? Your question is kinda unclear.
– Geo1088
Mar 23 at 15:21
@Geo1088 I updated the question, it should be clearer now.
– jafed
Mar 23 at 18:10