We help IT Professionals succeed at work.

Openning a hidden window

gbaren
gbaren asked
on
Medium Priority
3,213 Views
Last Modified: 2012-05-04
I need to open an invisible browser window and have the page loaded in the invisible window write to the document that loaded it.

1. How do I load an invisible window
2. How do I write to the document that loaded it

I'm writing for IE, no need for Netscape compatibility.

Thanks!
Comment
Watch Question

Commented:
I guess you can have an invisible window only by making use of frames. Say you have a frameset structure something like this

<frameset rows="0,*">
<frame name="frame1" href="page1.html">
<frame name="frame2" href="page2.html">
</frameset>

Now, when you open the page containing the frameset, you can see only one page i.e. page2.html. Page1.html is hidden.

You can write to the document by using

top.frame2.document.write(...)

Hope this helps !!!!!

Author

Commented:
Thank you for your input, but I already have this working with an <IFRAME>. And I want to avoid a frames page. There are side effects which I am hoping to avoid using a window.
Commented:
You can achieve it by positioning the window off the screen. Here is some code I've put together for you:


<html>
<head>
<script language="javascript">
<!--

var newwin = null;

function openHiddenWin(){
  var output = "<html><head></head><body><form name=\"frm1\">";
  output += "<input type=\"text\" name=\"text1\" value=\"howdy!\"";
  output += "</form></body></html>";
  newwin = window.open("", "hidwin", "width=10,height=10,left=" + (screen.width + 10));
  newwin.document.write(output);
  newwin.document.close();
}

function getValueFromHiddenWin(){
  if(newwin != null && !newwin.closed){
    alert(newwin.document.forms.frm1.text1.value);
  }
  else{
    alert("The hidden window isn't open yet!");
  }
}

function closeHiddenWin(){
  if(newwin != null && !newwin.closed){
    newwin.close();
  }  
}

//-->
</script>
</head>
<body>
<a href="#" onclick="openHiddenWin(); return false;">open &quot;hidden&quot; window</a><br>
<a href="#" onclick="getValueFromHiddenWin(); return false;">get value from text box in &quot;hidden&quot; window</a><br>
<a href="#" onclick="closeHiddenWin(); return false;">close &quot;hidden&quot; window</a><br>
</body>
</html>

:o)

Ant

Author

Commented:
I like it!

One thing: to avoid waiting for the window to open, I will have a script which runs in the new window onLoad event.

How would you write to the document that opened the current window?

Gary

Commented:
You want to "write" content to the parent window you mean?

Well to access the parent window you use:

window.opener

and then you can do things like:

window.opener.document.write("Hello!");
window.opener.document.close();

That will of course completely overwrite the page currently being displayed.

A common thing is to redirect the parent window e.g.

window.opener.location = "nextpage.html";

:o)

Ant

Author

Commented:
Ahh... window.opener - great!

I'm writing for IE, what I need to write is:

window.opener.document.<DivName>.innerHTML = "some text"

Actually, this is for domain name registration, the "some text" will be either a red X or a check box. It works from an IFRAME, it's just that each time I load the IFRAME, the calling document gets repositioned.

Thanks!

Commented:
My pleasure - thanks for the A!

:o)

Ant

Explore More ContentExplore courses, solutions, and other research materials related to this topic.