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;








1















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?










share|improve this question






























    1















    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?










    share|improve this question


























      1












      1








      1








      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?










      share|improve this question
















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 23 at 17:46







      AP.

















      asked Mar 23 at 16:22









      AP.AP.

      2,40963791




      2,40963791






















          1 Answer
          1






          active

          oldest

          votes


















          1














          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.






          share|improve this answer

























          • 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











          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
          );



          );













          draft saved

          draft discarded


















          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









          1














          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.






          share|improve this answer

























          • 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















          1














          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.






          share|improve this answer

























          • 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













          1












          1








          1







          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.






          share|improve this answer















          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.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          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

















          • 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



















          draft saved

          draft discarded
















































          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.




          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

          용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

          155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해