Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JScript to imitate CTRL-N ?

Status
Not open for further replies.

toolkit

Programmer
Aug 5, 2001
771
GB
In IE, pressing CTRL-N creates a new window, containing the same contents as the old window.
Does anyone know how to perform this in JScript?
Thanks, Neil :)
 
First of all, it happens only in IE. Other browsers (Mozilla, Opera - depending on it's settings) just opens a blank window.
It's rather easy to achieve what you want:

function loadNew()
{
url = location.href;
window.open(url,"","")
}

<a href=&quot;#&quot; onclick=&quot;loadNew()&quot;>CTRL+N emulation</a>
 
Unfortunately not so simple for:
[1] Frames. My link is in a sub frame.
[2] Dynamically written content.
I tried something like:
Code:
<input ... onclick=&quot;window.open(top.location.href,'_blank');&quot;>
This didn't work :-( What I would really like is:
Code:
<input ... onclick=&quot;top.clone()&quot;>

Anyone?? :)
 
Well, you didn't tell anything about additional requirements at the beginning.
In case of frames, do this:
url = parent.frame_name.location.href; - for particular frame,
And top.location.href - for entire frameset - should work as well, I really don't see any problem here.

Placing &quot;_blank&quot; at the 2nd parameter of window.open() is an error. It is valid only for <a href> targeting.
 
Thanks for the advice Starway :) Unfortunately I have tried all the techniques you suggest already, to no avail :(
 
try this :
function loadNew()
{
url = top.location.href;
MyWin = window.open(url,&quot;&quot;,&quot;&quot;);
MyWin.focus();
}

<a href=&quot;javascript:loadNew()&quot;>CTRL+N emulation</a>
 
Thanks for all the suggestions :). However, I have already tried top.location.href, as well as many others. The problem is that my top frame is generated dynamically by another window. What I have finally decided to try is:

[1] A button that stays dimmed until the top window is fully generated (that is, all the frames are rendered)
[2] Then somehow copy the rendered DOM document structure across using DocumentFragment, and Node methods....

Fun fun fun :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top