Forum Moderators: open

Message Too Old, No Replies

Making a page load itself into a new window

How to do this?

         

Nick_W

4:43 pm on Aug 31, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi everyone,

If I wanted to make a page load itself into a new window, how would I do it?

Thanks

Nick

rewboss

5:31 pm on Aug 31, 2002 (gmt 0)

10+ Year Member



Presumably, you could use a straightforward <a> tag with target attribute:

<a href="thispage.html" target="_blank">Load in new page</a>

Or with JavaScript:

window.open(self.location);

Nick_W

6:56 pm on Aug 31, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



window.open(self.location);

Yes, I want the page to automatically load iself as soon as the page is hit.

So presumable that, on the body load and unload?

Nick

rewboss

8:12 pm on Aug 31, 2002 (gmt 0)

10+ Year Member



Ah, there's a problem with that. It's a very efficient denial of service attack.

Think about it: the user downloads an HTML which includes, near the top, this tag:

<body onload="window.open(self.location);">

This causes a new window to open and will download the same HTML file into it. This HTML file includes this tag:

<body onload="window.open(self.location);">

This causes a new window to open and will download the same HTML file into it. This HTML file includes this tag:

<body onload.... Well, you get the idea. The process is repeated ad infinitum, new windows popping up all over the place until the system crashes.

I think you'd have to check the current window's URL with that of the window's opener if there is any. There are various problems with this: if your site has loaded into a window that was opened by a window on a different server, you will run into the JavaScript Same Origin security hobble. I suspect something like this would work:

if(opener && (opener.location && (opener.location.href!=self.location.href))) window.open(self.location);

I'm not sure, but give it a try.

Why do I test location.href and not just location? Because location is an object and will be passed by reference, not value: the expression opener.location!=self.location will always evaluate to true.

Nick_W

10:14 am on Sep 1, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's a very efficient denial of service attack.

Is that an attack on myself (my server) or the person's PC?

Nick

rewboss

2:36 pm on Sep 1, 2002 (gmt 0)

10+ Year Member



On the client's own PC. He would go to you site and suddenly window after window would pop up, eating memory until the whole system crashed.