Skip to content
On this page

View partial source

View source code of selected area.

js
javascript: function getSelSource() {
  x = document.createElement('div');
  x.appendChild(window.getSelection().getRangeAt(0).cloneContents());
  return x.innerHTML;
}

function makeHR() {
  return nd.createElement('hr');
}

function makeParagraph(text) {
  p = nd.createElement('p');
  p.appendChild(nd.createTextNode(text));
  return p;
}

function makePre(text) {
  p = nd.createElement('pre');
  p.appendChild(nd.createTextNode(text));
  return p;
}
nd = window.open().document;
ndb = nd.body;
if (
  !window.getSelection ||
  !window.getSelection().rangeCount ||
  window.getSelection().getRangeAt(0).collapsed
) {
  nd.title = 'Generated Source of: ' + location.href;
  ndb.appendChild(
    makeParagraph('No selection, showing generated source of entire document.')
  );
  ndb.appendChild(makeHR());
  ndb.appendChild(
    makePre('<html>\n' + document.documentElement.innerHTML + '\n</html>')
  );
} else {
  nd.title = 'Partial Source of: ' + location.href;
  ndb.appendChild(makePre(getSelSource()));
}
void 0;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

References

The code above was copied from the following page: