Ich möchte ein neues Fenster öffnen mit:
window.open('<myfile>.pdf','my window','resizable,scrollbars');
Das neue Fenster wird geöffnet, aber ich bekomme den Titel des Fensters nicht als "mein Fenster". Was könnte schief gehen?
Wenn Domäne gleich ist, können Sie den Titel eines neuen Fensters ändern
<script type="text/javascript">
var w = window.open('http://localhost:4885/UMS2/Default.aspx');
w.document.title = 'testing';
</script>
Hier ist meine Lösung, bitte überprüfen Sie dies:
var myWindow = window.open('<myfile>.pdf','my window','resizable,scrollbars');
myWindow.document.write('<title>My PDF File Title</title>');
Ich hoffe ich konnte helfen.
Das habe ich gemacht:
<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>
im HTML-Körper<U><A style="cursor: pointer;" onclick="OpenWindow()">Open in New Window</a></U>
Das JavaScript-Argument "title" ist eine Variable, die in JavaScript verwendet werden soll. Der eigentliche Titel, der oben im Fenster geschrieben wird, stammt normalerweise vom HTML-Tag <title>
. Dies ist jedoch nicht möglich, da Sie eine PDF-Datei anzeigen.
Wenn das neue Fenster eine Datei (zum Beispiel PDF) als URL enthält, ist es möglich, dass die Seite kein "head" -Tag hat.
Sie müssen zuvor einen hinzufügen, um den Titel zu ändern/hinzuzufügen.
jQuery:
var w = window.open('/path/to/your/file.pdf');// or any url
$(w.document).find('html').append('<head><title>your title</title></head>');
Native Js:
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'));
Wenn nun die Seite lange geladen ist, können Sie eine Onload-Überwachung und dann eine Zeitüberschreitung hinzufügen. In meinem Fall musste ich so schreiben:
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.
Der folgende Code funktioniert für Mozilla Firefox, IE 11 und 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";
In meinem Fall funktionierte es nur mit setTimeout wie folgt:
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
}
}
Um den Titel eines PDF in einem neuen Fenster zu ändern
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();
}
Onclick
<a onclick="titlepath('your url','what title you want')">pdf</a>