2017-04-04 45 views
1

我想从页面中获取document.write内的html,并加载,追加到另一个页面上的新div。这里是整个页面的源代码。我只是想拿到桌子追加到#newDIV获取页面内容,追加到脚本标记

<html> 

<head> 
    <link rel="alternate stylesheet" type="text/css" href="resource://gre-resources/plaintext.css" title="Wrap Long Lines"> 
</head> 

<body cz-shortcut-listen="true"> 
    <pre>document.write('<table align="center" cellspacing="1" class="report" id="livescoring"><caption><span>Live Scoring</span></caption><tbody><tr><th>Week 19</th></tr><tr class="oddtablerow"><td><a target="_blank" href="http://www03.myfantasyleague.com/2016/live_scoring_summary?L=75656&amp;W=19">Live Scoring Summary</a>\ 
</td></tr><tr class="eventablerow"><td><a target="_blank" href="http://www03.myfantasyleague.com/2016/live_scoring?L=75656&amp;W=19">Live Scoring Details</a>\ 
</td></tr></tbody></table>'); 
    </pre> 
</body> 

</html> 

我想要得到的“预”中创建的文档写表标签

我想简单地将内容加载到使用.load新的div,但没有奏效

因此,这将呈现一个新的页面上这样

<div id="newDIV"><table align="center" cellspacing="1" class="report" id="livescoring"><caption><span>Live Scoring</span></caption><tbody><tr><th>Week 19</th></tr><tr class="oddtablerow"><td><a target="_blank" href="http://www03.myfantasyleague.com/2016/live_scoring_summary?L=75656&amp;W=19">Live Scoring Summary</a> 

现场打分详细

+0

你可以重写你的问题更清楚。这并不是很清楚你在 –

+0

之后感谢迈克尔,我已经这样做了,希望它更清楚 – MShack

+0

让我看看我是否能够直接得到这个结果。您想要导航到另一个页面,在页面加载后,与您一起传输DOM元素并将其附加到该页面中的元素。是这个吗?这是我一整天听到的最疯狂的想法,在这里已经过了整整一天,哈哈。它不能完成,但有解决方法。 –

回答

1

正如@MichaelSeltenreich指出的那样,只有在同一个域中才能使用。在第一页,你需要的字符串存储的东西像

let text = document.querySelector('pre').innerHTML 
    .replace("document.write('","") 
    .replace("');",""); 
localStorage.setItem('myTable', text); 

...可能随后改变页面:

window.location.replace("/your-desired-path"); 

...和,

其他页面上
let text = localStorage.getItem('myTable'); 
// go wild... 
+0

谢谢,这工作 – MShack

+0

不客气。请注意我用'.replace()'改变了'.href ='。不同的是它现在不会在浏览器历史记录中创建一个点。这就像你直接导航到第二页。有它的方式,如何更方便。玩的开心! –

相关问题