2016-03-17 133 views
1
頁面

統一的字體大小我想開有一個叫divDiv1舊頁面內容相同的新的一頁新的一頁。 在我的JavaScript函數中,有一個newWindow變量,它由window.open命令返回,我將Div1的內部HTML寫入newWindow,我希望新頁面中的每個單獨文本的字體大小爲7px。下面是我寫的:文件撰寫與整個

newWindow.document.write('<html><head><title>Hello World</title>'); 
     newWindow.document.write('</head><body style="font-size:7px">'); 
     newWindow.document.write($('Div1').html()); 
     newWindow.document.write('</body></html>'); 

新的頁面呈現,但由於在Div1內容被splited到3個fieldset S,只有legend小號那些fieldset S的有他們的字體大小改爲7px的,該字段集內的一切仍然有默認的字體大小(大約11px)。如何將新頁面中的每個文本更改爲7px?我可以document.write鏈接到新頁面的新樣式表,但我更喜歡內聯樣式。謝謝。


舊頁面(ASP.net):

<div id="Div1" runat=server> 
    <fieldset> 
     <legend class="LLegends"> Header </legend> 
      <asp:FormView ID="FormView1" runat="server"> 
       contents that I want to be 7px in the new page 
      </asp:FormView> 
    </fieldset> 

    <!-- other 2 fieldsets with the same set up --> 
</div> 

LLegends(只類,它具有CSS樣式元素)

.LLegends {font-size: large;} 
+0

您必須向我們展示此處涉及的實際HTML。如果某些HTML標籤都有自己的'字體size'內嵌樣式設置或從一個樣式表CSS較高優先級繼承樣式,那麼你就''標籤樣式不會覆蓋這些。 – jfriend00

回答

0

不能對內嵌樣式的新頁面的body但我想我可以改變

newWindow.document.write('</head><body style="font-size:7px">'); 

要:

newWindow.document.write('<style>.body {"font-size:7px"}</style></head><body>'); 
0

你可以試試這個片斷。添加您的實際樣式,然後將它們與您的其他HTML附加到文檔中。 所以無法開啓新的窗口,所以試試這個網址:http://output.jsbin.com/sobewavagi

(function(undefined) { 
 
     /** 
 
     * 
 
     */ 
 
     'use strict'; 
 

 
     function addStyleOnOpen() { 
 
     var style, 
 
      stylesheet, 
 
      pageTitle = 'my title', 
 

 
      prnt = open(); 
 

 
     style = document.createElement("style"); 
 

 
     style.setAttribute('media', 'all'); 
 
     style.setAttribute('type', 'text/css'); 
 
     style.setAttribute('rel', 'stylesheet'); 
 

 
     style.appendChild(document.createTextNode("")); 
 
     prnt.document.head.appendChild(style); 
 

 
     stylesheet = style.sheet; 
 

 
     stylesheet.insertRule('body {width: 100% !important;margin: 0 !important;padding: 0 !important;line-height: 1.45;font-family: "Open Sans", sans-serif;color: #999;background: none;font-size: 14pt;}', 0); 
 

 
     stylesheet.insertRule('#new-window {color: green;}', stylesheet.cssRules.length); 
 

 
     stylesheet.insertRule('h1 {color: red;}', stylesheet.cssRules.length); 
 

 
     prnt.document.title = pageTitle; 
 
     prnt.document.body.insertAdjacentHTML('afterbegin', '\n <h1>Heading</h1> \n <p id="new-window">Hello World!</p>'); 
 
     } 
 

 
     document.getElementById('new-window').addEventListener('click', addStyleOnOpen, false); 
 

 

 
    }(undefined));
<a href="#" id="new-window">Open</a>

+0

我注意到,所以沒有爲我打開窗戶。我會更新片段。 – colecmc