Forum Moderators: coopster

Message Too Old, No Replies

Forcing a new browser window

new window?

         

Matthew1980

7:36 am on Apr 7, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there people of Webmasterworld,

I'm wondering if there is a way to use php to force a new browser window to open, effectively mimicing a link being clicked. I was wondering if there is a parameter within header("location: "); that could do this, but as yet I can't seem to find it.

I'm trying to avoid javascript, as there is no specific link, it just an if stating (pseudo code :)):-

if(isset(DEBUG) && DEBUG == "output"){
//force content into new window & redirect parent window to mainpage
}

Basically I have a constant defined in my defenitions file, it's value is set from a db call, so effectively depending on the value of DEBUG depends on whether or not the output is piped into a file or to a new browser window. Default is NULL (as the db field is enum, with either NULL, output, file as the options, NULL is no action obviously ;-) )

I hope that makes sense.

More than likely I am approaching this in a rather convoluted way, any suggestions welcome :)

Cheers,
MRb

Anyango

8:28 am on Apr 7, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



in my little knowledge, PHP will Never be able to open a new window, as it has no control over client. It has to be client side script, Javascript will do it for you easily, but then 99% of the times it will get blocked by either popup blocker or browser itself. Unless you call that javascript when user clicks a link

Matthew1980

8:54 am on Apr 7, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there Anyango,

Yeah, I hoped as there was a way to use header() to open a new window, other than that, can you still use target="_blank" to create a new window, reason I ask is that I am sure I read it somewhere that it is now depricated (?)

I suppose that I could use an if to invoke an onSubmit in the form when the value isset.

Mmm, I will have to think about this...

Cheers,
MRb

Anyango

10:47 am on Apr 7, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yep that will work, and _blank will also work. But here is one very important rule which popup blockers use.

"Is this new window, a result of user clicking a link ?"

If it is, you can many times get away with it. But if like done by code, most probably it will get blocked. Unles you are doing it in admin section for limitted users, they can then allow popups from your site.

Matthew1980

11:21 am on Apr 7, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there anyango,

I'm not worried about the user, it just something for myself that in the longrun *should* save me some manual time. For the timebeing I can do it, but if I can, I will consider it as something I can put in my snippets folder for use on other things ;-p

Thanks for the advice though.

Cheers,
MRb

rocknbil

7:45 pm on Apr 7, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I am sure I read it somewhere that it is now depricated (?)


It's the target attribute that'd depreicated in 4.01 strict and all flavors of XHTML, but not 4.01 transitional.

You can do this with Javascript, but use a routine that includes a full instance of the window including address bar, toolbars, etc. Attach it externally, it will validate.

If you don't mind invalidation of target=, it's a fair trade off that won't break the rest of the page.

Matthew1980

8:40 pm on Apr 7, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there Rocknbil,

Now that's timing :) I have just ~kinda implemented it, well at least the window opens and I have had to juggle the code a little, but I have got the window opening, with the desired content present, and as you hinted too, I have it validating as strict too. So, I'm happy with that, now I just (icing on the cake) would like to have the parent window redirect to the main page, though this is not a necessity, but I shall try.

Also, thanks for clearing up the target="_blank" question too, I knew something had changed, should have googled it really. I have my sgml parser on strict, and the tick is still there :)

Thanks for the tips.

Cheers,
MRb

briggl

3:21 pm on Apr 8, 2010 (gmt 0)

10+ Year Member



If the target attribute is deprecated is there something that is supposed to replace it?

rocknbil

8:05 pm on Apr 9, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



See above, client side scripting.

But.

It's coming back in HTML 5 [w3.org].

Also, the target attribute for the a and area elements is no longer deprecated, as it is useful in Web applications, e.g. in conjunction with iframe.