How do I prevent CSS interference in an injected piece of HTML?

前端 未结 3 1764
悲哀的现实
悲哀的现实 2021-01-05 22:43

I\'m currently developing a Safari extension that uses an injected script to further inject some HTML into the current webpage, as well as injecting some other scripts to ma

3条回答
  •  情深已故
    2021-01-05 23:21

    i have seen on different plugins that they put the code inside a iframe and they use JS to interact with the rest of the page, so you can not change the css inside.

    Also i have seen that when injecting html code,people sets the style of the plugin content using the "style" attribute inside the tags so the browser will give priority to the css inside the style attribute and not the css file. The idea is to override the css,usually with the "!important" clause. But you might have some problems on different browsers

    EDIT i forgot to say that my answer is on the case that you inject the code on someone's else page where you cannot control directly the css

提交回复
热议问题