开发者

Is there a way to change or reskin an incoming website on the fly?

开发者 https://www.devze.com 2023-01-06 11:48 出处:网络
I have a project where they want me to embed a website into a java application and they want the website to have a similar color scheme as the rest of the application. I know a lot about CSS and build

I have a project where they want me to embed a website into a java application and they want the website to have a similar color scheme as the rest of the application. I know a lot about CSS and building websites but I am not aware of a way to change the look of a website as it comes in on the fly. Is there someone who can help?

Update:

I don't have access to the header because it i开发者_如何转开发s not my website. To give more info about the project is we have a browser embedded in a java client application. The user needs to access a website that displays the contents of a database. I have no access to the original html or css from the site.

What i need is to change the background color and font sizes of the incoming webpage to match the look and feel of the java application.


One approach would be to replace their CSS with your own.

You could also take the approach used by the Stylish plugin, which involves a lot !important decelerations to override the site's CSS. Since this is a Java app, I assume the user will not have opportunity to supply their own CSS, so using !important here doesn't precisely go against the standard.


In your particular situation, I'd look into data scraping, all you need to do is scrape the website for the data, and then re-style it to present it how you want.

Good luck


The Greasemonkey add-on for Firefox does just this. You can write a bit of Javascript code and have it run when certain web pages load. One common thing to use it for is to make changes to the DOM to move page elements around, hide or resize elements, change colors, etc. There are a bunch of examples at userscripts.org if you want to get an idea of what I am talking about.

Your code would simply need to do something similar. Load the page (including the normal style sheets) and then use the DOM to make changes to style elements as desired. Browse through the source of the page to get the names/ids of important elements, and your code can key off of those. Loading an additional CSS file containing your changes is an option, but doing it programmatically will likely give you more flexibility in the event that the target website changes.


Depends on what do you use to show the pages in Java. Most browser implementations support dynamic changes to the DOM, so you can simply add a CSS file to header as a last element, and it will be applied.


you need to know the markup of the html / css so you can make the best skin.

you could theoretically do it by styling just the basic tags: h1...h6, p, etc... but it would not be as good and would probably fail to produce the best results at times and even produce horrible things at times.

if you KNOW the site markup then you can make a skin and simply use CSS/images to skin it as you wanted it.

just include your CSS markup LAST so that it overrides the one already present on the site that you want to skin differently.

should not be a difficult thing per se. the skin itself is probably the better (more effort required) part of the job.


On the fly, should mean changing the html fetched. So parsing and replacing tokens seems to be a/the way.

You could change the locations of the style sheet files by replacing the href value in a link that points to a css file, and set the value to your style sheet (a different URI).

<link type="text/css" href="mylocalURI" rel="stylesheet /> 
(this should be the result of a process/replacement)

I think you understand what should happend for inline styles.


I would use JTidy to normalize the original site HTML to XHTML, then use XSLT to filter only the interesting/relevant information, obtaining XML format; and finally (since I wouln't want to convert XML to objects), XSLT again to transform the "pure" XML into the HTML look & feel I need/want.

All of this can be assembled as streams, using more or less 4 Kb of buffer per filter (12 Kb total) per thread. Also meaning that it will run fast enough. And all built on standard, open-source available components.

Cheers.

0

精彩评论

暂无评论...
验证码 换一张
取 消