javascript - image returns value “null” using JS -
I have an image in my web page that I want to print using Javascript but the ID of the image in JS Is always helpless please advise me what you should do ..
& lt; Div class = "reportFieldsDiv" runat = "server" clientidmode = "static" & gt; & Lt; Table style = "width: 400px; margin: 10px 0px 0px 10px; boundary: 1 px solid black" & gt; & Lt; TR & gt; & Lt; TD & gt; & Lt; Img src = "~ / images / layout / testbase.jpg" alt = "id badge" id = "main image" /> & Lt; / TD & gt; & Lt; / TR & gt; & Lt; / Table & gt; & Lt; Div style = "border: 0 px solid black; padding: 5px 0px 0px 280px" & gt; & Lt; ASP: Button ID = "BTNPrint" Runat = "Server" text = "Print" width = "140px" /> & Lt; / Div & gt; & Lt; / Div & gt; & Lt; Script type = "text / javascript" & gt; Window.onload = function () {var image = document.getElementById ('main image'); Printimage (image); }; Function printImage (image) {var printWindow = window.open ('', 'print window', 'height = 400, width = 600'); PrintWindow.document.write ('
head & gt; Title & gt; Print Window & lt; / title & gt;'); PrintWindow.document.write ('& lt; img id = "main image" src = \' ... Images layout \ TestBadge.jpg '); PrintWindow.document.write (image.src); PrintWindow.document.write ('' '' & lt; / body & gt; & lt; / html & gt; '); PrintWindow.document.close (); PrintWindow.print (); } & Lt; / Script & gt;
You have been shown the ID below in the printWindow
document: < / P>
printWindow.document.write ('& lt; img id = "main image" src = ".. \ images \ layout \ TestBadge.jpg"');
Comments
Post a Comment