简体   繁体   English

非常先进的Java所见即所得编辑器

[英]Very Advanced Javascript WYSIWYG editor

I need a solution where a user could enter the URL of a web page in my system. 我需要一个解决方案,使用户可以在我的系统中输入网页的URL。 The page would load, and then the user could click a certain section that he wants to change. 页面将加载,然后用户可以单击他要更改的特定部分。 So basically what I need is, a way to display a web page inside my app (could possibly be done with frames but I'd prefer not to have a horizontal scroll bar), and then another way to let users select a block of text or a page element. 因此,基本上我需要的是一种在应用程序内显示网页的方法(可以用框架完成,但我不希望使用水平滚动条),然后通过另一种方式让用户选择文本块或页面元素。

Ie if a block of text is in a div , hovering above the text would outline that div using a faint green color (hovering away would remove this border/outline), and clicking the text would draw a solid green border around it to show that its been selected, and then some content on my page will show the id of the div, and let the user specify some other info that i need. 即,如果一个文本块位于div ,则将鼠标悬停在文本上方会使用淡绿色勾勒出该div的轮廓(悬停将删除该边框/轮廓线),单击该文本会在其周围绘制一个纯绿色边框以显示选择它,然后我页面上的某些内容将显示div的ID,并让用户指定我需要的其他信息。

So I probably need a way to get all the <div>s , <table>s , <span>s , <p>s and any other 'container' tags, and then have the ability to cause hovering/clicking of them to change their style.border property, and the ability to retrieve their id/name, 因此,我可能需要一种方法来获取所有<div>s<table>s<span>s<p>s和任何其他“容器”标签,然后能够使它们悬停/单击以更改其style.border属性以及获取其ID /名称的功能,

For a block of text the border could probably work, but what about images and such? 对于一块文本来说,边框可能会起作用,但是图像之类的呢? Also, what if a <div> doesn't have an ID/Name, how could it be specified? 另外,如果<div>没有ID /名称,该如何指定呢?

You could use <iframe> tags, then set contentEditable = on . 您可以使用<iframe>标记,然后将contentEditable = on设置contentEditable = on This way, the browser supplies the WYSIWYG features. 这样,浏览器就提供了所见即所得的功能。 The borders, etc. may not work, though. 但是,边框等可能无法工作。 Some code: 一些代码:

var idno = 0;

function addEditor(parent, url) {
    parent.innerHTML += '<iframe src="' + url + '" id="edit' + idno + '"></iframe>';
    var el = document.getElementById("edit" + idno);
    el.contentEditable = true;
    return el;
}

addEditor(document.body, "http://google.com").innerHTML += "Hello!";

Should work. 应该管用。

If they fit your context, you might consider doing this with either Adobe Flex or Microsoft Silverlight. 如果它们适合您的上下文,则可以考虑使用Adobe Flex或Microsoft Silverlight进行此操作。 Both provide the functionality and granularity of control that's more difficult to accomplish in javascript or with a framework, especially if you need to to work consistently with several browsers, across Windows, Mac, and Linux. 两者都提供了在javascript或框架中更难实现的控制功能和粒度,尤其是如果您需要在Windows,Mac和Linux上与多个浏览器保持一致的情况下。

Flex uses an enhanced version of javascript for its programming language. Flex将javascript的增强版本用于其编程语言。 Silverlight did similarly with version 1, although with version 2 they only support the .NET languages (which may be better, worse, or indifferent depending on your needs.) Silverlight在版本1中也做了类似的工作,尽管在版本2中,它们仅支持.NET语言(根据您的需要,它可能会更好,更坏或无动于衷。)

Both describe themselves as tools for RIAs (Rich Internet Applications). 两者都将自己描述为RIA(富Internet应用程序)的工具。

This is a very general question. 这是一个非常普遍的问题。 There are lots of content management systems around, that provides something like this. 周围有很多内容管理系统,它们提供了类似的内容。

Also, what if a <div> doesn't have an ID/Name, how could it be specified? 另外,如果<div>没有ID /名称,该如何指定呢?

You can identify a node in the DOM by an XPath path. 您可以通过XPath路径标识DOM中的节点。 Traverse upwards through the parentNode to create the path. 向上遍历parentNode以创建路径。

For a block of text the border could probably work, but what about images and such? 对于一块文本来说,边框可能会起作用,但是图像之类的呢?

You can set the border property of almost all elements in html. 您可以设置html中几乎所有元素的border属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM