PDA

View Full Version : window.location.href



surboomer
11-17-2005, 09:37 PM
Right, this is such a pain, I can't believe its not possible!

I am using window.location.href but can't appy a target blank to it! Just self or top...why is that?

Any other options?

window.open ?

Cheers
SBM

ddadmin
11-17-2005, 11:28 PM
Try:



window.parent.location="http://www.google.com"

This will cause Google.com to be loaded in the browser window, clearing any frames if it's inside one.

jscheuer1
11-18-2005, 03:37 AM
Just in case ddadmin has missed what I think the question is here, I think what you are looking for is the window.open() method. It is the javascript equivalent to the html anchor tag with the target attribute set to _blank. Here is how it is used to open a basic new window:

window.open('some.htm')

If you can follow this logic, the window.open() part replaces:

target="_blank"

and the 'some.htm' part replaces:

href="some.htm"

If ddadmin got it right, this post will self destruct in 10 seconds.

surboomer
11-18-2005, 06:04 AM
thank you both, and thank you mad professor for answering correctly!
:D

cracken
11-23-2007, 02:24 PM
Hi
I have an add on to this post.

I am a newbie at JavaScript.
Can the window.open() method be added to the following line of code so it redirects on the click to a new browser ?
onClick="window.location.href = 'some.htm'"

Thanks

Mark

jscheuer1
11-23-2007, 02:55 PM
<span onclick="var bob=window.open('','_blank');bob.location='some.htm';">Whatever</span>

But one can just as easily:


<span onclick="window.open('some.htm','_blank');">Whatever</span>

cracken
11-23-2007, 03:01 PM
Thats perfect !

Thankyou very much.

Mark

g78
04-20-2008, 03:16 PM
Hi i have a question a bit different that probably touch everything you wrote in this tread.

I need to open a pop up window from a list i generated from a database.

Up to now this is what i was using to see my results from my list.


<?php
[...]
echo ' <tr class="content" onmouseout="this.className=\'content\'" onmouseover="this.className=\'mouseover\'"
onclick="location.href=\'add.php?id='.$line['id'].'\'">';
[...]
?>


The problem is i need to make the page appear in a pop-up window.
I need to be able to set the width and height of that window also.
I tried several things but i still didn't found anything that worked since its in a <TR>.

Any tips or help would be greatly appreciated.
Thanks

G78.

Nile
04-20-2008, 03:51 PM
Try this:


<?php
[...]
echo ' <tr class="content" onmouseout="this.className=\'contenu\'" onmouseover="this.className=\'mouseover\'"
onclick="location.href=\'add.php?id='.$ligne[id].'\'">';
[...]
?>

g78
04-20-2008, 04:00 PM
Erm, are you saying it can't be done? :confused:

Its the exact same code.

Heres the full function.


<?php

function ShowContent($line) {

global $Columns;

echo ' <tr class="content" onmouseout="this.className=\'content\'" onmouseover="this.className=\'mouseover\'"
onclick="location.href=\'add.php?id='.$line['id'].'\'">';
foreach ($Columns as $col => $title) {
if ($line[$col]) {
echo '<td>';
echo htmlentities($line[$col]);
echo '</td>';
}
}
echo "</tr>\n";

}
?>

Nile
04-20-2008, 04:07 PM
It just took away a little thing, although I don't think that it'll work.

g78
04-20-2008, 04:29 PM
Well i didn't need any fix on it. :p

I only need to know how i should proceed to make a new window appear with predefined width and height when ill be clicking in one of those row.

It gets kinda complicated once it goes into PHP since we got to remove some of the '' and "" cause its a echo.
ie: <a href="http://www.google.com">Google it</a> --> echo "<a href=http://www.google.com>Google it</a>";

And because it ain't a <a href></a> but a <tr>, it seems like we cant do the same thing in it.

I know a bit my way around javascript, but i really dunno how to proceed for this.

Am checking if i can use location.href to do it and i already tried with winBRopen with no success.

Am guessing i need something in javascript, or is theres a easier way to do this?

akamaxbuz
04-27-2008, 07:02 PM
I am using dotmenu in http://systemarchitects.com/sysbonus/index.html
How can I get a new page (profile.html) to open in the same page (index.html)?

menu.addItem("PROFILE","window.open('profile.html')");

This opens a new window. I tried
menu.addItem("PROFILE","window.navigate('profile.html')");
but nothing happens.
Thanks

jscheuer1
04-27-2008, 07:41 PM
I am using dotmenu in http://systemarchitects.com/sysbonus/index.html
How can I get a new page (profile.html) to open in the same page (index.html)?

menu.addItem("PROFILE","window.open('profile.html')");

This opens a new window. I tried
menu.addItem("PROFILE","window.navigate('profile.html')");
but nothing happens.
Thanks


There probably is a more direct way to do this, but if:


menu.addItem("PROFILE","window.open('profile.html')");

opens in a new window. This should open in the current window:


menu.addItem("PROFILE","window.open('profile.html', '_self')");

With most menus of this sort:


menu.addItem("PROFILE","profile.html");

would be the more direct approach.

jscheuer1
04-27-2008, 08:12 PM
Well i didn't need any fix on it. :p

I only need to know how i should proceed to make a new window appear with predefined width and height when ill be clicking in one of those row.

It gets kinda complicated once it goes into PHP since we got to remove some of the '' and "" cause its a echo.
ie: <a href="http://www.google.com">Google it</a> --> echo "<a href=http://www.google.com>Google it</a>";

And because it ain't a <a href></a> but a <tr>, it seems like we cant do the same thing in it.

I know a bit my way around javascript, but i really dunno how to proceed for this.

Am checking if i can use location.href to do it and i already tried with winBRopen with no success.

Am guessing i need something in javascript, or is theres a easier way to do this?

OK, well I am assuming that you know how to work this into your PHP code or can figure it out. The javascript window.open() method accepts three main sorts of information:

URL
Target_or_Name
Specifications

Like so:


window.open(URL, Target_or_Name, Specifications);

Only URL is required. If these are already javascript varialbles, it can be as above, however - as is often the case, they are string values, so must be quoted with either single or double quotes (whichever fit the rest of the surrounding code best, or use escaped single or double quotes if existing surrounding quotes requires it*), ex (probably very close to what you need for your purposes):


window.open('some.htm', '_blank', 'width=300, height=250, location, scrolling, realizable');

For more on the available Specifications (the Target_or_Name can be any valid window name or valid link target designation, or be left empty, and must be an empty string if not used when Specifications are used) see one or more of the choices from:

http://www.google.com/search?client=opera&rls=en&q=window.open+method&sourceid=opera&ie=utf-8&oe=utf-8

The trickiest things to understand about the Specifications are:


If none are specified, all are enabled with width, height, top, and left at the browser's discretion.

If any are specified, all but the mandatory ones for that particular browser are either disabled or at the browsers discretion unless also specified.

Mentioning a specification that is true/false, yes/no, or 0/1 (basically known as boolean), makes it true. Not mentioning one of those type of specifications makes it false, if any other specifications have been mentioned

A user's browser settings and security features will override your specifications in some, often many, cases.


Browser settings can often override even any use of window open that doesn't target an existing window, and Specifications will not affect an existing window.

*escaping and/or just correctly utilizing quotes when using both PHP and javascript together can be tricky, but can almost always be worked out. Keep things as simple as possible.

seveninstl
04-30-2008, 08:20 PM
I've got a question on this issue... so I'm not starting a new thread, just adding to this.

I am using the following code:

<tr>
<td id="menuItem65" name="menuItem65" class="menuTable" onclick="javascript: window.open('http://www.somewhere.com', '_blank');" onmouseover="javascript:ddmenuOver('menuItem65');" onmouseout="javascript:ddmenuOut('menuItem65');">
Concierge Service
</td>
</tr>

This will not work from any page in my root directory (Linux/Apache server), but works fine from subdirectories (../pages/ for example).

I have tried removing the target peram "_blank" and I've also used the onclick in a span tag. Neither of these has changed the outcome.

Anyone have an idea why this is happening?

Thanks!

jscheuer1
04-30-2008, 08:42 PM
I've got a question on this issue... so I'm not starting a new thread, just adding to this.

I am using the following code:

<tr>
<td id="menuItem65" name="menuItem65" class="menuTable" onclick="javascript: window.open('http://www.somewhere.com', '_blank');" onmouseover="javascript:ddmenuOver('menuItem65');" onmouseout="javascript:ddmenuOut('menuItem65');">
Concierge Service
</td>
</tr>

This will not work from any page in my root directory (Linux/Apache server), but works fine from subdirectories (../pages/ for example).

I have tried removing the target peram "_blank" and I've also used the onclick in a span tag. Neither of these has changed the outcome.

Anyone have an idea why this is happening?

Thanks!

Looks to me that the script containing the function:


ddmenuOver()

is not on the page in the root. You may have an external script tag to the code for that function on the page in the root, but if so, the src attribute for that tag isn't valid in the root.

There is a possibility that it could be something else, very slight I believe, but I could be missing something. If you need more help:

Please post a link to the page on your site that contains the problematic code so we can check it out.

seveninstl
04-30-2008, 10:34 PM
The ddmenuOver and other js functions are in files in the js directory:

<script language="JavaScript" src="js/fhcc_general.js"></script>
<script language="JavaScript" src="js/navagateIndex.js"></script>

These files are the same files called by the pages in the '../pages/' subdirectory with the following code:

<script language="JavaScript" src="../js/fhcc_general.js"></script>
<script language="JavaScript" src="../js/navagateIndex.js"></script>

If I replace "javascript: window.open('http://www.somewhere.com');" with "javascript: window.location.href='http://www.somewhere.com';" the js executes without a problem. Of course, the new page is in the same browser window / tab instead of a new one (I really would like it to open in a new window / tab).

The url to the site is http://www.thefloridahotelorlando.com. Because this is a live site, I've changed the code to use the window.location.href version.

I can, of course, write my own function to open a new window / tab and send it the needed url. But, I would like to know why 'window.open()' will not work, but all the other js in the page does??????? :confused: :eek:

seveninstl
04-30-2008, 10:44 PM
Sorry for the time you might have spent trying to figure this one out.

I removed a form from the page earlier in the day. But, I still had an 'onload' call to a function that was trying to write to the fields in that form. This was causing the problem.

Again, sorry for wasting your time! And thanks for your help!! :)

mukeshftec
12-04-2009, 08:51 AM
HI there,

Whenever after clicked on submit the window.location="Url" has opened in Same window.. i want to open it new window. how can i do............

Pls help me........

Code .................
< ----------------------------------------------------------------------->
<SCRIPT LANGUAGE="JavaScript">

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
function Login(){
var done=0;
var username=document.login.username.value;
username=username.toLowerCase();
var password=document.login.password.value;
password=password.toLowerCase();
if (username=="mukesh1" && password=="mukesh1") { window.location="page2.html"; done=1; }
if (username=="mukesh2" && password=="mukesh2") { window.location="page3.html"; done=1; }
if (username=="member3" && password=="password3") { window.location="page3.html"; done=1; }
if (username=="member5" && password=="password5") { window.location="page3.html"; done=1; }
if (done==0) { alert("Invalid login!"); }
}
// End -->
</SCRIPT>

<!-- STEP TWO: Paste this code into the BODY of your HTML document -->

<BODY>

<center>
<form name=login>
<table width=225 border=1 cellpadding=3>
<tr><td colspan=2><center><font size="+2"><b>Members-Only Area!</b></font></center></td></tr>
<tr><td>Username:</td><td><input type=text name=username></td></tr>
<tr><td>Password:</td><td><input type=text name=password></td></tr>
<tr><td colspan=2 align=center><input type=button value="Login!" onClick="Login()"></td></tr>
</table>
</form>
</center>

<---------------------------------------------------------

Mukesh

jscheuer1
12-04-2009, 09:04 AM
Change:


window.location="page2.html"; done=1;

and similar to:


window.open("page2.html", "_blank"); done=1;