attribute javascript title window.open

javascript - attribute - ¿Cómo mostrar el título de la ventana usando window.open()?



title css (10)

Quiero abrir una nueva ventana usando:

window.open(''<myfile>.pdf'',''my window'',''resizable,scrollbars'');

Se abre la nueva ventana, pero no aparece el título de la ventana como "mi ventana". ¿Qué podría estar yendo mal?


Aquí está mi solución, por favor mira esto:

var myWindow = window.open(''<myfile>.pdf'',''my window'',''resizable,scrollbars''); myWindow.document.write(''<title>My PDF File Title</title>'');

Espero poder ayudar.


El argumento "título" de JavaScript es una variable que se utiliza dentro de JavaScript. El título real escrito en la parte superior de la ventana normalmente proviene de la etiqueta HTML <title> , pero no lo tiene porque está mostrando un PDF.


El siguiente código me funciona en Mozilla Firefox, IE 11 y Google Chrome.

var winUrl = ''target URL that needs to open in new window''; var _newWindow = window.open(winUrl, "_newWindow"); _newWindow.document.title = "My New Title";


Esto es lo que hice:

<script type="text/javascript"> function OpenWindow() { var pdf = ''<%= "PDFs/13.7/" + ddlLinkValidation.SelectedValue.ToString() + ".pdf" %>''; var win = window.open('''',''UATRpt'', ''menubar=0,location=0,toolbar=0,resizable=1,status=1,scrollbars=1''); if(win.document) { win.document.write(''<html><head><title>Your Report Title</title></head><body height="100%" width="100%"><iframe src="'' + pdf + ''" height="100%" width="100%"></iframe></body></html>''); } return true; } </script>

en cuerpo de HTML
<U><A style="cursor: pointer;" onclick="OpenWindow()">Open in New Window</a></U>


La única forma en que funcionó en mi caso fue usando setTimeout esta manera:

var mapWin = window.open('''', ''_blank'', ''''); // Opens a popup setWindowTitle(mapWin) // Starts checking function setWindowTitle(mapWin) { if(mapWin.document) // If loaded { mapWin.document.title = "Oil Field Map"; } else // If not loaded yet { setTimeout(setWindowTitle, 10); // Recheck again every 10 ms } }


Puede intentar capturar el evento window.onload para ese programa como se muestra a continuación:

var w = window.open(''https://your_website_url''); var title = ''Your Custom Title''; w.onload = function(){ w.document.title = title; };


Si el dominio es el mismo, entonces puede cambiar el título de la nueva ventana

<script type="text/javascript"> var w = window.open(''http://localhost:4885/UMS2/Default.aspx''); w.document.title = ''testing''; </script>


Si la nueva ventana tiene un archivo (PDF, por ejemplo) como una URL, es posible que la página no tenga una etiqueta de "encabezado" .

Tienes que agregar uno antes para modificar / agregar el título.

jQuery:

var w = window.open(''/path/to/your/file.pdf'');// or any url $(w.document).find(''html'').append(''<head><title>your title</title></head>'');

Js nativos:

var w = window.open(''/path/to/your/file.pdf'');// or any url w.document.getElementsByTagName(''html'')[0] .appendChild(document.createElement(''head'')) .appendChild(document.createElement(''title'')) .appendChild(document.createTextNode(''your title''));

Ahora, si la página es larga para cargar, puede agregar un reloj de carga, y también un tiempo de espera. En mi caso, tuve que codificar así:

var w = window.open(''/path/to/your/file.pdf'');// or any url w.onload = function(){ setTimeout(function(){ $(w.document).find(''html'').append(''<head><title>your title</title></head>''); }, 500); } // quite ugly hu !? but it works for me.


Para cambiar el título del pdf en la ventana recién abierta

function titlepath(path,name){ //In this path defined as your pdf url and name (your pdf name) var prntWin = window.open(); prntWin.document.write("<html><head><title>"+name+"</title></head><body>" + ''<embed width="100%" height="100%" name="plugin" src="''+ path+ ''" '' + ''type="application/pdf" internalinstanceid="21"></body></html>''); prntWin.document.close(); }

Al hacer clic

<a onclick="titlepath(''your url'',''what title you want'')">pdf</a>


var myWindow = window.open('''', '''', ''width=600,height=400''); setTimeout(function(){ myWindow.document.title = ''my new title''; }, 1000);

funciona cromo 2018