Dynamically added stylesheet only taken into account if first oneInsert CSS into loaded HTML in UIWebView / WKWebViewHow can I merge properties of two JavaScript objects dynamically?Event binding on dynamically created elements?How to measure time taken by a function to executeDynamically changing stylesheet path not working in IE and FirefoxHow do I make the first letter of a string uppercase in JavaScript?How to style a <select> dropdown with only CSS?Dynamically load and unload stylesheetsRound to at most 2 decimal places (only if necessary)Jquery .load not using stylesheetLoad local web files & resources in WKWebView
Is it standard for US-based universities to consider the ethnicity of an applicant during PhD admissions?
How was the blinking terminal cursor invented?
Do we see some Unsullied doing this in S08E05?
Is Precocious Apprentice enough for Mystic Theurge?
Cycling to work - 30mile return
Using 何 with the general counter ~つ
A person lacking money who shows off a lot
Why is the A380’s with-reversers stopping distance the same as its no-reversers stopping distance?
Find the area of the rectangle
Usage of the relative pronoun "dont"
Thread.sleep inside infinite while loop doesn't throw exception - why?
How to handle professionally if colleagues has referred his relative and asking to take easy while taking interview
What dog breeds survive the apocalypse for generations?
Why are lawsuits between the President and Congress not automatically sent to the Supreme Court
How does this piece of code determine array size without using sizeof( )?
How come Arya Stark didn't burn in Game of Thrones Season 8 Episode 5
How can I make dummy text (like lipsum) grey?
Why does Taylor’s series “work”?
Enqueue Queueable class multiple times
Square spiral in Mathematica
Resistor Selection to retain same brightness in LED PWM circuit
A latin word for "area of interest"
Why aren't satellites disintegrated even though they orbit earth within their Roche Limits?
bash: Counting characters within multiple files
Dynamically added stylesheet only taken into account if first one
Insert CSS into loaded HTML in UIWebView / WKWebViewHow can I merge properties of two JavaScript objects dynamically?Event binding on dynamically created elements?How to measure time taken by a function to executeDynamically changing stylesheet path not working in IE and FirefoxHow do I make the first letter of a string uppercase in JavaScript?How to style a <select> dropdown with only CSS?Dynamically load and unload stylesheetsRound to at most 2 decimal places (only if necessary)Jquery .load not using stylesheetLoad local web files & resources in WKWebView
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I am adding dynamically 2 style sheets in a WKWebView having local content loaded using loadFileURL.
The cocoa application calls the following javascript snippet to add the stylesheets.
var link = document.createElement('link');
link.setAttribute('rel', 'stylesheet');
link.type = 'text/css';
link.title = csstype;
link.href = cssSheetPath1;
document.head.appendChild(link);
var link = document.createElement('link');
link.setAttribute('rel', 'stylesheet');
link.type = 'text/css';
link.title = csstype;
link.href = cssSheetPath2;
document.head.appendChild(link);
The 2 stylesheets are located in the same directory. I can either load the first one or the second one, but never both. If I try to load both, only the first one is applied.
Any idea from where the issue can come from?
javascript css macos cocoa wkwebview
add a comment |
I am adding dynamically 2 style sheets in a WKWebView having local content loaded using loadFileURL.
The cocoa application calls the following javascript snippet to add the stylesheets.
var link = document.createElement('link');
link.setAttribute('rel', 'stylesheet');
link.type = 'text/css';
link.title = csstype;
link.href = cssSheetPath1;
document.head.appendChild(link);
var link = document.createElement('link');
link.setAttribute('rel', 'stylesheet');
link.type = 'text/css';
link.title = csstype;
link.href = cssSheetPath2;
document.head.appendChild(link);
The 2 stylesheets are located in the same directory. I can either load the first one or the second one, but never both. If I try to load both, only the first one is applied.
Any idea from where the issue can come from?
javascript css macos cocoa wkwebview
add a comment |
I am adding dynamically 2 style sheets in a WKWebView having local content loaded using loadFileURL.
The cocoa application calls the following javascript snippet to add the stylesheets.
var link = document.createElement('link');
link.setAttribute('rel', 'stylesheet');
link.type = 'text/css';
link.title = csstype;
link.href = cssSheetPath1;
document.head.appendChild(link);
var link = document.createElement('link');
link.setAttribute('rel', 'stylesheet');
link.type = 'text/css';
link.title = csstype;
link.href = cssSheetPath2;
document.head.appendChild(link);
The 2 stylesheets are located in the same directory. I can either load the first one or the second one, but never both. If I try to load both, only the first one is applied.
Any idea from where the issue can come from?
javascript css macos cocoa wkwebview
I am adding dynamically 2 style sheets in a WKWebView having local content loaded using loadFileURL.
The cocoa application calls the following javascript snippet to add the stylesheets.
var link = document.createElement('link');
link.setAttribute('rel', 'stylesheet');
link.type = 'text/css';
link.title = csstype;
link.href = cssSheetPath1;
document.head.appendChild(link);
var link = document.createElement('link');
link.setAttribute('rel', 'stylesheet');
link.type = 'text/css';
link.title = csstype;
link.href = cssSheetPath2;
document.head.appendChild(link);
The 2 stylesheets are located in the same directory. I can either load the first one or the second one, but never both. If I try to load both, only the first one is applied.
Any idea from where the issue can come from?
javascript css macos cocoa wkwebview
javascript css macos cocoa wkwebview
edited Mar 23 at 17:46
AP.
asked Mar 23 at 16:22
AP.AP.
2,40963791
2,40963791
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You have to run that twice. Make a function and then call it for both stylesheets.
const createLink = (cssSheetPath) =>
const link = document.createElement('link');
link.setAttribute('rel', 'stylesheet');
link.type = 'text/css';
link.href = cssSheetPath;
document.head.appendChild(link);
createLink('style1.css');
createLink('style2.css');
added a running code example: codesandbox example
If you dont use a function, then you should try to use two different var names:
var link = document.createElement('link');
link.setAttribute('rel', 'stylesheet');
link.type = 'text/css';
link.title = csstype;
link.href = cssSheetPath1;
document.head.appendChild(link);
var link1 = document.createElement('link');
link1.setAttribute('rel', 'stylesheet');
link1.type = 'text/css';
link1.title = csstype;
link1.href = cssSheetPath2;
document.head.appendChild(link1);
I can't test it with WKWebView.
This is exactly what I am doing and what is not working hence my question.
– AP.
Mar 23 at 17:29
you define only one link element in your example. So, you overwrite it, when you try to use this element for two stylesheets.
– d-h-e
Mar 23 at 17:33
Initial question edited to remove any ambiguity.
– AP.
Mar 23 at 17:46
added a link with an working example
– d-h-e
Mar 23 at 17:47
1
i found this -> SO answer. Maybe it helps.
– d-h-e
Mar 23 at 19:07
|
show 2 more comments
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%2f55315840%2fdynamically-added-stylesheet-only-taken-into-account-if-first-one%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
You have to run that twice. Make a function and then call it for both stylesheets.
const createLink = (cssSheetPath) =>
const link = document.createElement('link');
link.setAttribute('rel', 'stylesheet');
link.type = 'text/css';
link.href = cssSheetPath;
document.head.appendChild(link);
createLink('style1.css');
createLink('style2.css');
added a running code example: codesandbox example
If you dont use a function, then you should try to use two different var names:
var link = document.createElement('link');
link.setAttribute('rel', 'stylesheet');
link.type = 'text/css';
link.title = csstype;
link.href = cssSheetPath1;
document.head.appendChild(link);
var link1 = document.createElement('link');
link1.setAttribute('rel', 'stylesheet');
link1.type = 'text/css';
link1.title = csstype;
link1.href = cssSheetPath2;
document.head.appendChild(link1);
I can't test it with WKWebView.
This is exactly what I am doing and what is not working hence my question.
– AP.
Mar 23 at 17:29
you define only one link element in your example. So, you overwrite it, when you try to use this element for two stylesheets.
– d-h-e
Mar 23 at 17:33
Initial question edited to remove any ambiguity.
– AP.
Mar 23 at 17:46
added a link with an working example
– d-h-e
Mar 23 at 17:47
1
i found this -> SO answer. Maybe it helps.
– d-h-e
Mar 23 at 19:07
|
show 2 more comments
You have to run that twice. Make a function and then call it for both stylesheets.
const createLink = (cssSheetPath) =>
const link = document.createElement('link');
link.setAttribute('rel', 'stylesheet');
link.type = 'text/css';
link.href = cssSheetPath;
document.head.appendChild(link);
createLink('style1.css');
createLink('style2.css');
added a running code example: codesandbox example
If you dont use a function, then you should try to use two different var names:
var link = document.createElement('link');
link.setAttribute('rel', 'stylesheet');
link.type = 'text/css';
link.title = csstype;
link.href = cssSheetPath1;
document.head.appendChild(link);
var link1 = document.createElement('link');
link1.setAttribute('rel', 'stylesheet');
link1.type = 'text/css';
link1.title = csstype;
link1.href = cssSheetPath2;
document.head.appendChild(link1);
I can't test it with WKWebView.
This is exactly what I am doing and what is not working hence my question.
– AP.
Mar 23 at 17:29
you define only one link element in your example. So, you overwrite it, when you try to use this element for two stylesheets.
– d-h-e
Mar 23 at 17:33
Initial question edited to remove any ambiguity.
– AP.
Mar 23 at 17:46
added a link with an working example
– d-h-e
Mar 23 at 17:47
1
i found this -> SO answer. Maybe it helps.
– d-h-e
Mar 23 at 19:07
|
show 2 more comments
You have to run that twice. Make a function and then call it for both stylesheets.
const createLink = (cssSheetPath) =>
const link = document.createElement('link');
link.setAttribute('rel', 'stylesheet');
link.type = 'text/css';
link.href = cssSheetPath;
document.head.appendChild(link);
createLink('style1.css');
createLink('style2.css');
added a running code example: codesandbox example
If you dont use a function, then you should try to use two different var names:
var link = document.createElement('link');
link.setAttribute('rel', 'stylesheet');
link.type = 'text/css';
link.title = csstype;
link.href = cssSheetPath1;
document.head.appendChild(link);
var link1 = document.createElement('link');
link1.setAttribute('rel', 'stylesheet');
link1.type = 'text/css';
link1.title = csstype;
link1.href = cssSheetPath2;
document.head.appendChild(link1);
I can't test it with WKWebView.
You have to run that twice. Make a function and then call it for both stylesheets.
const createLink = (cssSheetPath) =>
const link = document.createElement('link');
link.setAttribute('rel', 'stylesheet');
link.type = 'text/css';
link.href = cssSheetPath;
document.head.appendChild(link);
createLink('style1.css');
createLink('style2.css');
added a running code example: codesandbox example
If you dont use a function, then you should try to use two different var names:
var link = document.createElement('link');
link.setAttribute('rel', 'stylesheet');
link.type = 'text/css';
link.title = csstype;
link.href = cssSheetPath1;
document.head.appendChild(link);
var link1 = document.createElement('link');
link1.setAttribute('rel', 'stylesheet');
link1.type = 'text/css';
link1.title = csstype;
link1.href = cssSheetPath2;
document.head.appendChild(link1);
I can't test it with WKWebView.
edited Mar 23 at 18:04
answered Mar 23 at 16:28
d-h-ed-h-e
1,7611313
1,7611313
This is exactly what I am doing and what is not working hence my question.
– AP.
Mar 23 at 17:29
you define only one link element in your example. So, you overwrite it, when you try to use this element for two stylesheets.
– d-h-e
Mar 23 at 17:33
Initial question edited to remove any ambiguity.
– AP.
Mar 23 at 17:46
added a link with an working example
– d-h-e
Mar 23 at 17:47
1
i found this -> SO answer. Maybe it helps.
– d-h-e
Mar 23 at 19:07
|
show 2 more comments
This is exactly what I am doing and what is not working hence my question.
– AP.
Mar 23 at 17:29
you define only one link element in your example. So, you overwrite it, when you try to use this element for two stylesheets.
– d-h-e
Mar 23 at 17:33
Initial question edited to remove any ambiguity.
– AP.
Mar 23 at 17:46
added a link with an working example
– d-h-e
Mar 23 at 17:47
1
i found this -> SO answer. Maybe it helps.
– d-h-e
Mar 23 at 19:07
This is exactly what I am doing and what is not working hence my question.
– AP.
Mar 23 at 17:29
This is exactly what I am doing and what is not working hence my question.
– AP.
Mar 23 at 17:29
you define only one link element in your example. So, you overwrite it, when you try to use this element for two stylesheets.
– d-h-e
Mar 23 at 17:33
you define only one link element in your example. So, you overwrite it, when you try to use this element for two stylesheets.
– d-h-e
Mar 23 at 17:33
Initial question edited to remove any ambiguity.
– AP.
Mar 23 at 17:46
Initial question edited to remove any ambiguity.
– AP.
Mar 23 at 17:46
added a link with an working example
– d-h-e
Mar 23 at 17:47
added a link with an working example
– d-h-e
Mar 23 at 17:47
1
1
i found this -> SO answer. Maybe it helps.
– d-h-e
Mar 23 at 19:07
i found this -> SO answer. Maybe it helps.
– d-h-e
Mar 23 at 19:07
|
show 2 more comments
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%2f55315840%2fdynamically-added-stylesheet-only-taken-into-account-if-first-one%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