2016-07-15 86 views
0

我有一个包含滑块的URL(http://www.basic-slider.com/)。我想要的是通过转义将整个页面内容放入JavaScript变量中,然后通过innerHTML或jQuery .html函数将此内容放置在我的空身标记中。使用JavaScript在div中呈现整个页面的HTML

代码只是放在body标签中,但它不像原始页面那样工作。我必须显示它与原始页面完全相同。

我不能使用iframe或任何XMLHTTP方法。下面是上述对应的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> 

有谁请告诉我的解决方案,使其工作完全像原来的页面。不要担心CSS路径和JS路径。对我而言,这绝对是绝对的。

+0

我能问的内容,为什么你想呈现一个div整个网站..? –

+0

因为我必须在我的智能电视应用程序中脱机显示网页的一些内容 –

+0

但是,为什么您需要该JavaScript?为什么不能把HTML文件放在html文件中? – Esko

回答

0

您需要创建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); 
}); 
+0

我已经告诉过,我不能使用iframe –

+0

@ManishJangir您无法使用iframe的具体原因? – gurvinder372

+0

由于该应用程序将运行在三星智能电视,并且不允许使用iframe –

相关问题