Set title in popup

Can a title be set in a popup?

I have this in javascript:

var popup = window.open('......'); popup.document.title = "my title"; 

but that will not work. Unable to see any title

EDIT: The popup popup shows up as .aspx and it has a title tag, but it still doesn't show up in the popup.

+6
source share
4 answers

Since popup.onload doesn't seem to work, here is a workaround: http://jsfiddle.net/WJdbk/ .

 var win = window.open('', 'foo', ''); // open popup function check() { if(win.document) { // if loaded win.document.title = "test"; // set title } else { // if not loaded yet setTimeout(check, 10); // check in another 10ms } } check(); // start checking 
+16
source

I had problems with the accepted answer until I realized that if you open the existing page slow , which already has a <title> browser 1) set your title, then 2) after the document fully loads it, it (re ) will set a popup name with a "normal" value.

So, introducing a reasonable delay ( openPopupWithTitle function):

 var overridePopupTitle = function(popup, title, delayFinal, delayRepeat) { // /questions/897755/set-title-in-the-window-popup/3204648#3204648 // delay writing the title until after it fully loaded, // because the webpage actual title may take some time to appear if(popup.document) setTimeout(function() { popup.document.title = title; }, delayFinal || 1000); else setTimeout(function() { overridePopupTitle(popup, title); }, delayRepeat || 100); } var openPopupWithTitle = function(url, title, settings, delay) { var win = window.open(url, title, settings); overridePopupTitle(win, title, delay); return win; } 
+4
source

None of these answers worked for me. I tried to open a popup with a PDF inside and kept getting permission denied, trying to set the title using the above methods. Finally, I found another position that pointed me in the right direction. Below is the code I used.

Source: How to set a title in a popup window when a URL points to a PDF file

  var winLookup; var showToolbar = false; function openReportWindow(m_title, m_url, m_width, m_height) { var strURL; var intLeft, intTop; strURL = m_url; // Check if we've got an open window. if ((winLookup) && (!winLookup.closed)) winLookup.close(); // Set up the window so that it centered. intLeft = (screen.width) ? ((screen.width - m_width) / 2) : 0; intTop = (screen.height) ? ((screen.height - m_height) / 2) : 0; // Open the window. winLookup = window.open('', 'winLookup','scrollbars=no,resizable=yes,toolbar='+(showToolbar?'yes':'no')+',height=' + m_height + ',width=' + m_width + ',top=' + intTop + ',left=' + intLeft); checkPopup(m_url, m_title); // Set the window opener. if ((document.window != null) && (!winLookup.opener)) winLookup.opener = document.window; // Set the focus. if (winLookup.focus) winLookup.focus(); } function checkPopup(m_url, m_title) { if(winLookup.document) { winLookup.document.write('<html><head><title>' + m_title + '</title></head><body height="100%" width="100%"><embed src="' +m_url + '" type="application/pdf" height="100%" width="100%" /></body></html>'); } else { // if not loaded yet setTimeout(checkPopup(m_url, m_title), 10); // check in another 10ms } } 
+2
source

Try it, it will work.

 var timerObj, newWindow; function openDetailsPopUpWindow(url) { newWindow = window.open(url, '', 'height=500,width=700,menubar=no,resizable=yes,scrollbars=yes'); timerObj = window.setInterval("fun_To_ReTitle('~~newTitle~~ ')", 10); } function fun_To_ReTitle(newTitle){ if (newWindow.document.readyState == 'complete') { newWindow.document.title=newTitle; window.clearInterval(timerObj); } } 
-1
source

Source: https://habr.com/ru/post/897755/


All Articles