...

View Full Version : Open URL in another tab/window



Gardy
11-17-2010, 12:21 PM
Hey all,

Just wondering if there is a way of opening a location in a new tab/window on the users browser, without the user having to click any thing?

Basically, my code allows the user to select an XML file which is then manipulated and saved to the server (need this as a record of what has been edited), and as the final step I'd like the file displayed to the user, but in another tab.

Thanks.

olidenia
11-17-2010, 12:28 PM
Is this what you are looking for?
It can be done with javascript, modifying the automatic redirect script:

You can edit the Timeout to 0 if you want it to redirect instantly.


<script type="text/javascript"><!--
setTimeout('Redirect()',4000);
function Redirect()
{
window.open = '<?php echo "url_of_document.xml"; ?>';
}
// --></script>


I have edited it to "window.open" so it opens a new window.

Gardy
11-17-2010, 12:34 PM
Thanks for the quick reply. It's pretty much what I am trying to do, only I'd like the file opened in a new tab/window so that the original page is still there.

Also, just tried the code you supplied and it's giving me 'Error on page'.

Thanks.

olidenia
11-17-2010, 12:39 PM
Ok, sorry.

This will work, you can adjust other elements also.


<script type="text/javascript"><!--
setTimeout('Redirect()',0);
function Redirect()
{
window.open('location_document.xml','mywin','left=20,top=20,width=500,height=500,toolbar=1,resizable =0');
}
// --></script>

Gardy
11-17-2010, 12:55 PM
The code is pretty self explanitory, thanks for that.

Plugged it in and still getting 'Error on page' though. If I change the timeout the 'Error on page' message does not kick in until after the the function fires. the file location is correct, as tried printing to screen and it works fine.

Thanks.

olidenia
11-17-2010, 01:57 PM
Thats strange, it works fine on my browser, I have replaced the url with http://google.com and it works fine.

Here is the exact script:


<script type="text/javascript"><!--
setTimeout('Redirect()',1000);
function Redirect()
{
window.open('http://google.com' , 'mywin' , 'left=20,top=20,width=500,height=500,toolbar=1,resizable=0');

}
// --></script>

Gardy
11-17-2010, 02:10 PM
Hmm, it works with Google, but will not work with my XML file - even if I make a clickable link to the file location it doesn't want to know, which is odd as the location is correct. Guess I'll have to put this on the back burner for the time being!

Thanks for the help.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum