8 gru 2012

Wyrażenie reguralne wykorzystanie w funkcji replace

function open_popup(url, w, h, t, l) {
  let param = popup_param(w, h, t, l);
  let Win = window.open("",'popup_window',param);
  Win.focus();
  return Win;
};
  
function program_print() {
  let el = document.getElementById('program-list');
  if(el!=undefined) {
    let Win=open_popup();
    let html=el.innerHTML;
    html=html.replace('program_print','window.print','g');
    html=html.replace(/<input\b[^>]*?/ig, "");
    Win.document.write(html);
  }
};

Wyrażenie regularne wykorzystanie w funkcji replace. Kod html pobierany jest z doma strona i przekley do nowego okna.

15 paź 2009

Dynamiczne dodanie markera span

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
 <head>
  <title> New Document </title>
  <script src="debug_js.js" type="text/javascript"></script>
  <script language="JavaScript">
  <!--
 function getE(id) {
  return document.getElementById(id);
 }

 function test() {
  deb_write(deb_prop(getE('tests'),true));
 }

function test2() {
      var div = document.createElement("span");
      div.style.font = '12px Arial, Verdana, Tahoma';
      div.style.position = "absolute";
   div.style.background = '#fefefe';
     div.style.padding = '2px';
   div.id = "s1";
   div.innerHTML = 'Warszawa, Warszawa, Warszawa, Warszawa';
   var d2 = getE('tests2');
      d2.appendChild(div);

deb_write(deb_prop(getE('s1'),true));
 }

 //-->
  </script>
 </head>

<body>
  <div id="tests">Polska Warszawa Polska Warszawa</div>
  <div id="tests2"></div>

  <input type="button" value="Test" onclick="test()">
  <input type="button" value="Test2" onclick="test2()">
 </body>
</html>
13 gru 2008

Drukowanie fragmentu strony

function print_frag(id) {
  var div;

  div = document.getElementById(id);
  okno = window.open("", "", "toolbar=0, location=0, resizable=1, directories=0, status=1, menubar=1, scrollbars=1, height=800, width=700, top=80, left=350");
  var html = div.innerHTML;

  html = '<html><head><link rel="stylesheet" href="<a href="http://kody.wig.pl/style.css" class="mce_ws_kod">http://kody.wig.pl/style.css</a>" type="text/css" /></head><body>' + html + '</body></html>';

  okno.document.write(html);
  //okno.print();
  okno.focus();
}
<a href="javascript:print_content('fragment')">Drukuj</a>