[英]Get html of current page store that html and use it later
I am create a tool where users can create their social share bar, but now I would like to create an in text styling feature so they set this piece of html in text to render the social share buttons: 我正在创建一个工具,用户可以在其中创建他们的社交共享栏,但是现在我想创建一个文本内样式设置功能,以便他们将这段HTML文本设置为呈现社交共享按钮:
<div id="fs_social-bar-wrapper"></div>
Than I have a function determine html which look like this: 比我有一个确定html的函数看起来像这样:
function determineHtml(){
var socialWrapper = document.querySelector(".socialShare").outerHTML;
var shareBarStyling = localStorage.getItem("shareBarStyling");
if(shareBarStyling === "floating_bar" || shareBarStyling === "expanding_bar"){
document.querySelector("#shareButton-code").innerHTML += socialWrapper;
} else if(shareBarStyling === "inline_bar"){
document.querySelector("#shareButton-code").innerHTML += `<div id="fs_social-bar-wrapper"></div>`;
}
}
This is all good and renders the social bar wrapper div but how can I later append the var socialWrapper = document.querySelector(".socialShare").outerHTML;
这一切都很好,并且渲染了社交栏包装器div,但是我以后如何追加
var socialWrapper = document.querySelector(".socialShare").outerHTML;
to the wrapper. 到包装纸。
So basically when the user finishes the creation they get a piece of code and here is the function which needs to append the current html later on. 因此,基本上,当用户完成创建时,他们会得到一段代码,这是以后需要附加当前html的函数。
function appendInlineHtml(){
document.querySelector("#fs_social-bar-wrapper").innerHTML = document.querySelector(".socialShare").outerHTML;
}
FYI: the output needs to work stand alone, ofcourse the above is not working because the selector .socialShare
is not available in other documents. 仅供参考:输出需要单独工作,当然上述内容不起作用,因为选择器
.socialShare
在其他文档中不可用。
So how can I store the current html of document.querySelector(".socialShare")
to render this later on in a stand alone document. 因此,我如何存储
document.querySelector(".socialShare")
的当前html,以便稍后在独立的文档中进行呈现。
If you use jQuery, 如果您使用jQuery,
var html = $("html").html();
If want to use pure JavaScript, 如果要使用纯JavaScript,
var html = document.documentElement.innerHTML;
You can html
use it later. 您可以稍后使用
html
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.