I am trying to rename a new tab I am opening up. This new tab contains an iframe
with an image as the source. This is how I am opening the tab, but can’t seem to get document.title
to work.
var customTab = window.open();
customTab && customTab.document.title = 'My new tab';//this doesn't work
customTab &&
customTab.document.write(
'<iframe src="' +
myImage +
'" style="border: none;"></iframe>'
);
Any ideas would be much appreciated.
2
Answers
If I understand correctly, you should try this:
The issue with setting the
document.title
in your code is likely due to the fact that the content of the newly opened window is dynamically generated with aniframe
, and thedocument.title
might not be accessible immediately after thewindow.open()
call.replace
customTab && customTab.document.title = 'My new tab';
with
if (customTab) customTab.document.title = 'My new tab';
You can’t assign a value to a variable inside an
&&
expression