how to set document title of new open window? - javascript

I am doing as below code to set document title for new open window
var downloadWindow = window.open("https://www.google.com/", "_blank");
downloadWindow.document.title = "my title";
If we try to execute above snippet in console in google chrome, we can see while loading, We can see "my title", but same behaviour I want to be in internet explore?
How we can achieve same behaviour in internet explore?

Try this
var downloadWindow = window.open("https://www.google.com/", "_blank");
downloadWindow.document.write('<title>my title</title>');

I think that due to security reasons, you will not able to see the modified title on the newly open window.
As a workaround, I suggest you try to display the alert message that informs the user that he is opening the downloading window.
Example:
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<script>
alert("You are moving to download window...");
var downloadWindow = window.open("https://example.com", "_blank");
</script>
</head>
<body>
Test page
</body>
</html>
Let us know if you have any further questions. We will try to provide suggestions for it.

Related

new window screenshot failed

I am trying to screenshot page created in new window, not popup but in new tab. Code now is simple. And page can be created.
However my goal is to make Full page screenshot of it. I used in Chrome - "Full Page Screen Capture " and in Firefox top screen captures - all of them greyed out - meaning impossible to capture entire page.
screenshot fialed
Code:
<!doctype html>
<head>
<title>New Window Screenshot</title>
</head>
<body>
<script>
function newWindow() {
var w = window.open('', '_blank');
w.document.write('Loading preview...');
}
</script>
<button onclick="newWindow()">Click me</button>
</body>
</html>
code
Please, no need of html2canvas. I just need to lunch some screencapturers. And my guess, well I don't know... Please help!

window.open Named Window is opening new window on each click

On launching a window using window.open(), a new instance of browser is getting launched on button click every time, even if the calling function is having named window.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<script type="text/javascript">
function OpenNamedWindow() {
var w2 = window.open("http://stackoverflow.com", "myWindow", "width=500px;height=500px");
}
</script>
<input type="button" onclick="OpenNamedWindow();" value="Launch App" />
</body>
</html>
After launching the page when I try to access window.name, it shows empty.
I did some search and looks like cross domain is causing the issue.
How can I load the page in same instance instead of launching a new browser window all the time?
This is a trick
function openInNewTab(url) {
var win = window.open(url, '_blank');
win.focus();
}
But even this, perhaps should not work in all browser depending on users configuration
This topic is still here in stackoverflow.
try to check it by yourself at the following link
Open a URL in a new tab (and not a new window) using JavaScript
It opens only one window at a time:
var window_name = null; // global
...
function open_new_window() {
if (window_name && !window_name.closed) {
window_name.close();
window_name = window.open(....);
}

why can't I get the content of another window?

I am a javascript beginner . I wrote a javascript code to open a website in new window and then get the content of that new window and display it in the first window .. and this is the code :
<!DOCTYPE html>
<html><head></head><body>
<div id="display"></div>
<script type="text/javascript">
var newwin=window.open("http://www.w3schools.com");
newwin.onload=function ()
{display.innerHTML = newwin.document.documentElement.innerHTML;};
</script>
</body></html>
It didn't work .. the web site opened in the new window but the content didn't appear in the first window .. why?
thanks in advance.
Use _parent as a second parameter to position your webpage. (BTW I am assuming you are allowing popups in your browser settings)
var newwin=window.open("http://www.w3schools.com", "_parent");
You cannot do this if the child window is from a different domain. Each domain is sandboxed from the others for security reasons.
There are 2 errors that prevent you:
Different domains
Even if same domain, you set onload function after calling window.open(). So the new "onload" behavior never runs
Solution for same domain:
<!DOCTYPE html>
<html><head></head><body>
<div id="display"></div>
<script type="text/javascript">
var w=window.open("another.html");
var tid = setInterval function () {
if (w.document.readyState !== 'complete')
return;
clearInterval(tid);
display.innerHTML = w.document.documentElement.innerHTML);
}, 100);
</script>
</body></html>

Popup window in Javascript

In Javascript, I want to open my window.html file in a popup window. But it doesn't display any text. Just a blank page.
This is index.html:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css" />
<script language="javascript">
var newwindow;
function popit(url){
newwindow = window.open(
url, '', "status=yes, height=500; width=500; resizeable=0");
}
</script>
</head>
<body>
CLICK ME!
</body>
</html>
window.html:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p>SAMPLE TEXT</p>
</body>
</html>
Why doesn't it display any text?
javascript:popit(window.html);
Replace with:
javascript:popit('window.html');
Your click handler code is syntactically incorrect:
CLICK ME!
Always, always have your developer console open to check for JavaScript errors! (edit — actually in this case there wouldn't have been an error; window.html would resolve to undefined probably! Still, keep the console open :-)
Also note that I used an "onclick" attribute instead of "href".
A GOOD working code with NO crashes.
Simple and what makes this code better is that you can use it in a JavaScript file separately and have it fairing to more then one file with the same popup size even though its different pages on popups.
Javascript
// Popup window code
function MyPopUp(url) {
popupWindow = window.open(
url,'popUpWindow','height=454,width=580,left=0,top=200,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes')
}
HTML
My PopUp
NOTE: You can also use this as onload in body for example <body onload="JavaScript:MyPopUp('MyDirectory/Page.html');"> and it will aslo work on onmouseover and others... though I do not advise this unless you want to piss off the clients visiting your page.

Why doesn't this JavaScript run in Firefox?

It certainly runs on IE6.
Why doesn't this JavaScript run in Mozilla Firefox?
<html>
<head>
<title>JavaScript Popup Example 3</title>
</head>
<SCRIPT language="JavaScript1.2">
function MyClass()
{
this.OpenWindow = function()
{
var r = window.open ('', 'mywindow', 'location=1,status=1,scrollbars=1,width=100,height=100');
r.moveTo(0,0);
r.location.href = 'http://www.google.com';
}
}
</SCRIPT>
<body onload="javascript: new MyClass().OpenWindow()">
<H1>JavaScript Popup Example 3</H1>
</body>
</html>
It runs just fine in my FF. For me the popup blocker is catching it.
Did you notice that little bar just below the tabs selection
alt text http://support.mozilla.com/img/wiki_up/86c0e1094489ddd5611008de57d0afed-1249166734-294-5.png
Check here for more information + images: FF Pop-up blocker
Just go to the FF menu -> option -> content -> block-pop-up-windows
Uncheck the option, click OK and try reload the page. It should now work fine for you. Also, don't forget to tick the check box again if you worry about security.

Categories