简体   繁体   English

使用JavaScript在div中呈现整个页面的HTML

[英]Render whole page HTML in a div using Javascript

I've a URL ( http://www.basic-slider.com/ ) that contains a slider. 我有一个包含滑块的URL( http://www.basic-slider.com/ )。 What I want is to get the whole page content in a javascript variable by escaping it and then place this content in my empty body tag through innerHTML or jQuery .html function. 我想要的是通过转义将整个页面内容包含在javascript变量中,然后通过innerHTML或jQuery .html函数将此内容放在我的空body标签中。

The code is simply being put in the body tag but its not working like original page. 只是将代码放在body标签中,但是它不能像原始页面那样工作。 I've to show it exactly same as original page. 我必须显示它与原始页面完全相同。

I can't use iframe or any XMLHTTP method. 我不能使用iframe或任何XMLHTTP方法。 Here is the code for the above corresponding URL: 以下是上述对应网址的代码:

    <!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<script src="jquery-2.2.4.min.js"></script>
<script src="mustache.js"></script>
<script>
var strVar="";
strVar += "<!DOCTYPE html>";
strVar += "<!--[if lt IE 7]>      <html class=\"no-js lt-ie9 lt-ie8 lt-ie7\"> <![endif]-->";
strVar += "<!--[if IE 7]>         <html class=\"no-js lt-ie9 lt-ie8\"> <![endif]-->";
strVar += "<!--[if IE 8]>         <html class=\"no-js lt-ie9\"> <![endif]-->";
strVar += "<!--[if gt IE 8]><!--> <html class=\"no-js\"> <!--<![endif]-->";
strVar += " <head>";
strVar += "     <meta charset=\"utf-8\">";
strVar += "     <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge,chrome=1\">";
strVar += "     <title>Basic jQuery Slider - Responsive slideshows for featured content<\/title>";
strVar += "     <meta name=\"description\" content=\"A simple, no-frills, robust jQuery plugin for creating simple, responsive slideshows for your featured content. Simple to use, theme and customise.\">";
strVar += "     <link href='http:\/\/fonts.googleapis.com\/css?family=Source+Code+Pro|Coda|Open+Sans:400,700' rel='stylesheet' type='text\/css'>";
strVar += "     <link href=\"\/\/maxcdn.bootstrapcdn.com\/font-awesome\/4.1.0\/css\/font-awesome.min.css\" rel=\"stylesheet\">";
strVar += "     <link rel=\"stylesheet\" href=\"css\/bootstrap.min.css\">";
strVar += "     <style>";
strVar += "         body {";
strVar += "             padding-top: 60px;";
strVar += "             padding-bottom: 40px;";
strVar += "         }";
strVar += "     <\/style>";
strVar += "     <link rel=\"stylesheet\" href=\"http://www.basic-slider.com\/css\/main.css\">";
strVar += "     <link rel=\"stylesheet\" href=\"http://www.basic-slider.com\/css\/prism.css\">";
strVar += "";
strVar += "     <script src=\"http://www.basic-slider.com\/js\/vendor\/modernizr-2.6.1-respond-1.1.0.min.js\"><\/script>";
strVar += " <\/head>";
strVar += " <body>";
strVar += "";
strVar += "     <div class=\"container\">";
strVar += "         <div class=\"row\">";
strVar += "             <header class=\"span12\">";
strVar += "                 <h1>Basic jQuery Slider<\/h1>";
strVar += "                 <h2>Simple to use, simple to theme, simple to customise<\/h2>";
strVar += "             <\/header>";
strVar += "             <div class=\"span12\" id=\"slider\">";
strVar += "                 <ul class=\"bjqs\">";
strVar += "                 <li><img src=\"img\/banner01.jpg\" title=\"Automatically generated caption\"><\/li>";
strVar += "                 <li><img src=\"img\/banner02.jpg\" title=\"Automatically generated caption\"><\/li>";
strVar += "                 <li><img src=\"img\/banner03.jpg\" title=\"Automatically generated caption\"><\/li>";
strVar += "                 <\/ul>";
strVar += "             <\/div>";
strVar += "<div class=\"span12 leaderboard-ad\">";
strVar += "<script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script>";
strVar += "<!-- Leaderboard -->";
strVar += "<ins class=\"adsbygoogle\"";
strVar += " style=\"display:inline-block;width:728px;height:90px\"";
strVar += " data-ad-client=\"ca-pub-7070404889996835\"";
strVar += " data-ad-slot=\"7960663502\"><\/ins>";
strVar += "<script>";
strVar += "(adsbygoogle = window.adsbygoogle || []).push({});";
strVar += "<\/script>";
strVar += "<\/div>";
strVar += "             <div class=\"span12 text\">";
strVar += "                 <h3>Purpose<\/h3>";
strVar += "";
strVar += "                 <p>There are a lot of jQuery content sliders out there. Most of them are loaded with cool features and skins, which are great if it is exactly what you are looking for, but more often than not you need to customise it for your own needs and it can be difficult cutting through the bloat of a full featured slider.<\/p>";
strVar += "";
strVar += "                 <p>Basic jQuery Slider has been developed to be as simple and lightweight as possible. Only the essential functionality has been included combined with clean semantic mark-up. This means instead of removing features and bending it to suit your needs, you can use this slider and as a base and with a little bit of CSS and JavaScript knowledge, you can extend it to be as feature rich, or as simple, as you need.<\/p>";
strVar += "";
strVar += "                     <h3>Download<\/h3>";
strVar += "";
strVar += "                 <section class=\"clearfix\">";
strVar += "                     <div class=\"download\">";
strVar += "                         <p>You can download the plugin for free, however if you'd like to support the ongoing hosting and development of the plugin, you can optionally purchase it for $3 - the cost of your morning coffee :)<\/p>";
strVar += "";
strVar += "                         <div class=\"buttons\">";
strVar += "                             <a class=\"btn btn-success\" style=\"font-size: 20px; padding: 20px;\" href=\"https:\/\/gumroad.com\/l\/XsbID\"><i class=\"fa fa-smile-o\"><\/i> Download with donation<\/a>";
strVar += "                             <a style=\"display: block; padding: 20px; text-align: center;\" href=\"http:\/\/github.com\/jcobb\/basic-jquery-slider\/\"><i class=\"icon-download-alt icon-white\"><\/i> Download for Free<\/a>";
strVar += "                         <\/div>";
strVar += "                     <\/div>";
strVar += "";
strVar += "                 <div class=\"ad-space\">";
strVar += "";
strVar += "";
strVar += "                     ";
strVar += "<script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script>";
strVar += "<!-- LREC -->";
strVar += "<ins class=\"adsbygoogle\"";
strVar += " style=\"display:inline-block;width:336px;height:280px\"";
strVar += " data-ad-client=\"ca-pub-7070404889996835\"";
strVar += " data-ad-slot=\"2053730701\"><\/ins>";
strVar += "<script>";
strVar += "(adsbygoogle = window.adsbygoogle || []).push({});";
strVar += "<\/script>";
strVar += "                 <\/div>";
strVar += "                 <\/section>";
strVar += "";
strVar += "                 <h3 style=\"clearfix\">Usage<\/h3>";
strVar += "";
strVar += "                 <h5>Plugin dependancies<\/h5>";
strVar += "";
strVar += "                 <p>There are two core files required to get up and running with Basic jQuery Slider, the JavaScript plugin and the base css.  The only dependancy is jQuery, so you will also need to make sure you have the latest version of the jQuery library included in your page. <\/p>";
strVar += "";
strVar += "                 <pre><code class=\"language-markup\">&lt;!-- Include the jQuery library (local or CDN) --&gt;";
strVar += "&lt;script src=\"http:\/\/code.jquery.com\/jquery-latest.min.js\"&gt;&lt;\/script&gt;";
strVar += "";
strVar += "&lt;!-- Include the plugin *after* the jQuery library --&gt;";
strVar += "&lt;script src=\"bjqs.min.js\"&gt;&lt;\/script&gt;";
strVar += "";
strVar += "&lt;!-- Include the basic styles --&gt;";
strVar += "&lt;link type=\"text\/css\" rel=\"Stylesheet\" href=\"bjqs.css\" \/&gt;<\/code><\/pre>";
strVar += "";
strVar += "                 <h5>Markup<\/h5>";
strVar += "";
strVar += "                 <p>The basic markup for the plugin is as follows.<\/p>";
strVar += "";
strVar += "                 <ul>";
strVar += "                     <li>An outer container which the plugin will be attached to,<\/li>";
strVar += "                     <li>An unordered list element with a class name of bjqs, and<\/li>";
strVar += "                     <li>Individual list elements for each slide.<\/li>";
strVar += "                 <\/ul>";
strVar += "<pre><code class=\"language-markup\">&lt;div id=\"my-slideshow\"&gt;";
strVar += " &lt;ul class=\"bjqs\"&gt;";
strVar += "     &lt;li&gt;&lt;!-- Any content you like --&gt;&lt;\/li&gt;";
strVar += "     &lt;li&gt;&lt;!-- Can go inside these slides--&gt;&lt;\/li&gt;";
strVar += " &lt;\/ul&gt;";
strVar += "&lt;\/div&gt;<\/code><\/pre>";
strVar += "";
strVar += "                 <h5>Activation<\/h5>";
strVar += "                 <p>The final step is to invoke the plugin and attach it to the outer-most dom element. You can then pass in a variety of key : value pairs to configure the slider.<\/p>";
strVar += "";
strVar += "<pre><code class=\"language-javascript\">jQuery(document).ready(function($) {";
strVar += " $('#banner-fade').bjqs({";
strVar += "     'height' : 320,";
strVar += "     'width' : 620,";
strVar += "     'responsive' : true";
strVar += " });";
strVar += "});";
strVar += "<\/code><\/pre>";
strVar += "";
strVar += "<div class=\"span12 leaderboard-ad\">";
strVar += "<script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script>";
strVar += "<!-- Leaderboard Bottom -->";
strVar += "<ins class=\"adsbygoogle\"";
strVar += " style=\"display:inline-block;width:728px;height:90px\"";
strVar += " data-ad-client=\"ca-pub-7070404889996835\"";
strVar += " data-ad-slot=\"3251262300\"><\/ins>";
strVar += "<script>";
strVar += "(adsbygoogle = window.adsbygoogle || []).push({});";
strVar += "<\/script>";
strVar += "<\/div>";
strVar += "";
strVar += "                 <h3>Options<\/h3>";
strVar += "";
strVar += "                 <p>Here is a full list of all the possible parameters which can used to configure the plugin and their default values.<\/p>";
strVar += "                 <pre><code class=\"language-javascript\">\/\/ width and height need to be provided to enforce consistency";
strVar += "\/\/ if responsive is set to true, these values act as maximum dimensions";
strVar += "width : 700,";
strVar += "height : 300,";
strVar += "";
strVar += "\/\/ animation values";
strVar += "animtype : 'fade', \/\/ accepts 'fade' or 'slide'";
strVar += "animduration : 450, \/\/ how fast the animation are";
strVar += "animspeed : 4000, \/\/ the delay between each slide";
strVar += "automatic : true, \/\/ automatic";
strVar += "";
strVar += "\/\/ control and marker configuration";
strVar += "showcontrols : true, \/\/ show next and prev controls";
strVar += "centercontrols : true, \/\/ center controls verically";
strVar += "nexttext : 'Next', \/\/ Text for 'next' button (can use HTML)";
strVar += "prevtext : 'Prev', \/\/ Text for 'previous' button (can use HTML)";
strVar += "showmarkers : true, \/\/ Show individual slide markers";
strVar += "centermarkers : true, \/\/ Center markers horizontally";
strVar += "";
strVar += "\/\/ interaction values";
strVar += "keyboardnav : true, \/\/ enable keyboard navigation";
strVar += "hoverpause : true, \/\/ pause the slider on hover";
strVar += "";
strVar += "\/\/ presentational options";
strVar += "usecaptions : true, \/\/ show captions for images using the image title tag";
strVar += "randomstart : true, \/\/ start slider at random slide";
strVar += "responsive : true \/\/ enable responsive capabilities (beta)<\/code><\/pre>";
strVar += "";
strVar += "             <\/div>";
strVar += "         <\/div>";
strVar += "     <\/div>";
strVar += " ";
strVar += "";
strVar += "     <script src=\"\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/1.8.2\/jquery.min.js\"><\/script>";
strVar += "     <script>window.jQuery || document.write('<script src=\"http://www.basic-slider.com\/js\/vendor\/jquery-1.8.2.min.js\"><\\/script>')<\/script>";
strVar += "";
strVar += "     <script src=\"http://www.basic-slider.com\/js\/vendor\/bootstrap.min.js\"><\/script>";
strVar += "     <script src=\"http://www.basic-slider.com\/js\/bjqs-1.3.min.js\"><\/script>";
strVar += "     <script src=\"http://www.basic-slider.com\/js\/main.js\"><\/script>";
strVar += "             <script src=\"http://www.basic-slider.com\/js\/vendor\/prism.js\"><\/script>";
strVar += "";
strVar += "<!-- TEH GOOGLES -->";
strVar += "<script type=\"text\/javascript\">";
strVar += "";
strVar += " var _gaq = _gaq || [];";
strVar += " _gaq.push(['_setAccount', 'UA-25642114-1']);";
strVar += " _gaq.push(['_trackPageview']);";
strVar += "";
strVar += " (function() {";
strVar += " var ga = document.createElement('script'); ga.type = 'text\/javascript'; ga.async = true;";
strVar += " ga.src = ('https:' == document.location.protocol ? 'https:\/\/ssl' : 'http:\/\/www') + '.google-analytics.com\/ga.js';";
strVar += " var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);";
strVar += " })();";
strVar += "";
strVar += "<\/script>";
strVar += "";
strVar += "<!-- Woopra -->";
strVar += "<script type=\"text\/javascript\">";
strVar += " function woopraReady(tracker) {";
strVar += " tracker.setDomain('basic-slider.com');";
strVar += " tracker.setIdleTimeout(300000);";
strVar += " tracker.track();";
strVar += " return false;";
strVar += " }";
strVar += " (function() {";
strVar += "     var wsc = document.createElement('script');";
strVar += "     wsc.src = document.location.protocol+'\/\/static.woopra.com\/js\/woopra.js';";
strVar += "     wsc.type = 'text\/javascript';";
strVar += "     wsc.async = true;";
strVar += "     var ssc = document.getElementsByTagName('script')[0];";
strVar += "     ssc.parentNode.insertBefore(wsc, ssc);";
strVar += " })();";
strVar += "<\/script>";
strVar += "";
strVar += "<!-- Gauges -->";
strVar += "<script type=\"text\/javascript\">";
strVar += " var _gauges = _gauges || [];";
strVar += " (function() {";
strVar += "     var t   = document.createElement('script');";
strVar += "     t.type  = 'text\/javascript';";
strVar += "     t.async = true;";
strVar += "     t.id    = 'gauges-tracker';";
strVar += "     t.setAttribute('data-site-id', '4f471b24f5a1f55972000042');";
strVar += "     t.src = '\/\/secure.gaug.es\/track.js';";
strVar += "     var s = document.getElementsByTagName('script')[0];";
strVar += "     s.parentNode.insertBefore(t, s);";
strVar += " })();";
strVar += "<\/script>";
strVar += " <\/body>";
strVar += "<\/html>";

$(document).ready(function(){
    var newhtml = $.parseHTML(strVar);
    document.getElementById('body').innerHTML += strVar;

    //eval($('#body').find('script').text());
});

</script>
</head>
<body id="body">

</body>
</html> 

Could anybody please tell me the solution to make it work exactly like original page. 有人可以告诉我解决方案以使其完全像原始页面一样工作。 Don't worry about the css paths and JS paths. 不用担心css路径和JS路径。 They will be absolute in my case. 在我看来,它们是绝对的。

You need to create an iframe inside the div and set the contents of that iframe 您需要在div内创建一个iframe并设置该iframe的内容

$(document).ready(function(){
    var newhtml = $.parseHTML(strVar);
    document.getElementById('body').innerHTML += "<iframe id='ifr1'></iframe>";
    document.getElementById('ifr').src = "data:text/html;charset=utf-8," + escape(strVar);
});

如何刷新<div>在 html 而不是整个页面</div><div id="text_translate"><p>我想刷新 html 页面中的特定部分(包含表单),而不是 Django 模板中的整个页面。当用户提交重定向到下一个问题的表单时,表单包含问题和选择。(base.ZFC35FDC70D5FC69D269883A82E 用于创建的脚本)倒计时器)</p><p> question_details.html</p><pre> {% extends 'app/base.html' %} {% block content %} &lt;div&gt; &lt;h2&gt;score -{{user.userextend.score}}&lt;/h2&gt; &lt;form action="{% url 'app:detail' quiz_id=que.quiz.id question_id=que.id %}" method="post" id="user_form"&gt; {% csrf_token %} {% for choice in que.answer_set.all %} &lt;input type="radio" name="choice" id="choice{{ forloop.counter }}" value="{{ choice.id }}"&gt; &lt;label for="choice{{ forloop.counter }}"&gt;{{ choice.answer }}&lt;/label&gt;&lt;br&gt; {% endfor %} &lt;input type="submit" value="Next"&gt; &lt;/form&gt; &lt;/div&gt; {% endblock %}</pre></div> - How to refresh <div> in html and not the whole page

暂无
暂无

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

相关问题 使用 div class 不会呈现 html 页面 - using a div class doesnt render html page 更新div标签,而无需使用JavaScript刷新整个页面 - Update div tag without refresh the whole page using JavaScript 虽然使用JavaScript刷新div标签会刷新整个页面 - While div tag refresh using JavaScript is refreshing the whole page 使用 javascript 渲染 DIV - Render DIV using javascript 使用javascript将HTML页面中的div下载为pdf - Download a div in a HTML page as pdf using javascript 如何使用Javascript或jQuery在div中呈现html代码 - How can I render html code in a div using Javascript or jQuery 如何刷新<div>在 html 而不是整个页面</div><div id="text_translate"><p>我想刷新 html 页面中的特定部分(包含表单),而不是 Django 模板中的整个页面。当用户提交重定向到下一个问题的表单时,表单包含问题和选择。(base.ZFC35FDC70D5FC69D269883A82E 用于创建的脚本)倒计时器)</p><p> question_details.html</p><pre> {% extends 'app/base.html' %} {% block content %} &lt;div&gt; &lt;h2&gt;score -{{user.userextend.score}}&lt;/h2&gt; &lt;form action="{% url 'app:detail' quiz_id=que.quiz.id question_id=que.id %}" method="post" id="user_form"&gt; {% csrf_token %} {% for choice in que.answer_set.all %} &lt;input type="radio" name="choice" id="choice{{ forloop.counter }}" value="{{ choice.id }}"&gt; &lt;label for="choice{{ forloop.counter }}"&gt;{{ choice.answer }}&lt;/label&gt;&lt;br&gt; {% endfor %} &lt;input type="submit" value="Next"&gt; &lt;/form&gt; &lt;/div&gt; {% endblock %}</pre></div> - How to refresh <div> in html and not the whole page 无法插入“ </div><div> &#39;使用javascript或jquery在html页面中的位置 - Cannot insert '</div> <div>' to a position in html page using javascript or jquery 嵌入式JavaScript-将HTML呈现到页面 - Embedded JavaScript - render HTML to page 如何使用javascript和/或html在div中显示返回的html页面 - How to display returned html page in a div using javascript and/or html
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM