...

View Full Version : Go here or there? It depends



cunning-fox
06-21-2002, 05:15 AM
Hi,

I want to try to bring visitors to 2 different sites, depending on a variable. It has to work on all major browsers.

This is the scenario:

A visitor goes to my main page. They click a link that pops up a new window. And the url to that page depends upon whether or not they have a certain other window open. So if the visitor has that certain other window open, then the page that they opened would go to www.yahoo.com. If they don't, they go to www.excite.com instead. Can anyone come up with a script?

A thanks goes out to all repliers

cunning-fox
06-21-2002, 05:33 PM
Is this possible anyone?

scroots
06-21-2002, 06:34 PM
it is possible,i believe as you can detect if a window is open or not via its name a believe.

scroots

foss
06-21-2002, 06:43 PM
hi!

if it was your homepage, that opened the other sites in new windows, there will no problem. If you want to check, if the user opened a new site in a new Browser-Window by his own, it will be impossible, my opinion.

in the case that your page opens a new window, you can check if this window has the url you are searching for.

for example:

your site opened Yahoo with variable in a javascript:

var YahooWin= window.open("http://www.yahoo.com","YahooWindow","width=300,height=200");

then you can check, if the window is still open with "Name.closed"

if (YahooWin.closed==true) alert("Window closed");
if (YahooWin.closed==false) alert("Window open");

to search for the URL in this window use the following term

var URL=YahooWin.location.href;
alert(URL);

this will show you, what site is opened in the window. You could use this also to check the url, with if (URL== "..... or if (URL!=.....

to check this things it is obsolent, that you have opened the pages in new windows with the way i told you above. The opening should be done with an variable .
Than there shouldn't be problems.

cunning-fox
06-22-2002, 02:20 AM
Hi,

Once again thanks for all the replies.

I'm not sure that I explained everything so well, so I'll try to use more names.

A visitor goes to www.myaddress.com/index.html, they click and open a new window named www.myaddress.com/login.html and login. When they go to click on a basic link on my site, they open another window named www.myaddress.com/link.html, this page should check to see that the window- www.myaddress.com/login.html is present. If it is, then www.myaddress.com/link.com will be forwarded to www.yahoo.com. If not, then it will be forwarded to www.excite.com. Can anyone kind of recap on the last script to fit the above.

Much appreciation and thanks

cunning-fox
06-22-2002, 06:09 PM
can this be done?:)

ACJavascript
06-22-2002, 11:59 PM
Will this work for ya??

-----------

<script language="javascript">

var login=window.open('login.html','loginpage')

function search(){

if(login.closed==true){
window.open("http://www.yahoo.com","yahooWindow")
}else{
window.open("http://www.excite.com","ExciteWindow")
}
}

</script>


<a href="javascript:search()">Click here</a>

cunning-fox
06-23-2002, 05:32 AM
ALMOST done... It's great, but I don't want the login.html to load by itself. I want the user to click to open login.html. Everything else is good. Anyone able to convert it?

You all are doing a great job:thumbsup:

cunning-fox
06-24-2002, 01:15 AM
Does anyone have an idea?

ACJavascript
06-24-2002, 01:32 AM
Does this work for ya fox,
its a little different from the last one but it does the same.

If the person clicks the long link, " true " is written to the hidden textbox.

Then when someone clicks on another link with the search function on it, it checks to see if the hidden textbox has " true " writtin in it. If it does it opens yahoo. If it doesn't then it opens excite. So it pretty much does the same thing

----------


<script language="javascript">

function login(){
var lg=window.open("Login.html","LoginPage")
document.forms[0].loginTrue.value="true"
}
function search(){

if(document.forms[0].loginTrue.value=="true"){
window.open("http://www.yahoo.com","YahooPage")
}else{
window.open("http://www.excite.com","ExcitePage")
}
}

</script>

<a href="javascript:login()">Login Here</a>

<form>
<input type="hidden" name="loginTrue">
</form>

<a href="javascript:search()">Click here</a>

--------

Hope this helps :D:D:D

cunning-fox
06-24-2002, 03:06 AM
Hi,

I tried that ACJ, but each hyperlink goes to the below, and in the same window. What happened?


C:\Documents and Settings\Administrator\My Documents\My Webs\myweb5\java script:search()

C:\Documents and Settings\Administrator\My Documents\My Webs\myweb5\java script:login()

If you can, try to work within this script, because i have multiple links on the same page I need to do this with, and naming needs to be easy. Maybe if you just defined login under "search()" to equal the name of the login window, instead of a variable. I don't know, I can only do so much with javascript. What do you think?

<script language="javascript">

var login=window.open('login.html','login')

function search(){

if(login.closed==true){
window.open("http://www.yahoo.com","yahooWindow")
}else{
window.open("http://www.excite.com","ExciteWindow")
}
}

</script>


<a href="javascript:search()">Click here</a>


Thanks

ACJavascript
06-24-2002, 03:10 AM
putting this will make the window open into a new window

<a href="javascript:login();" target="_new">Login here</a>
<BR>
<a href="javascript:search();" target="_new">Click here</a>

glenngv
06-24-2002, 03:22 AM
correct ACJavascript, but, no offense, it seems you treat _new as a predefined target property value. Please correct me if I'm wrong with my impression. I've also seen this before in the previous post maybe in the old forum.
The predefined values of target are: _blank, _self, _top. Yes of course your code will work because if you provide a window/frame name that does not exist, a new window will be opened.

Just clarifying for the sake of all beginners. :)


Originally posted by ACJavascript
putting this will make the window open into a new window

<a href="javascript:login();" target="_new">Login here</a>
<BR>
<a href="javascript:search();" target="_new">Click here</a>

ACJavascript
06-24-2002, 04:31 PM
YOUR 100% right, but they do both work the same. But I should of used the right code. hehehe:thumbsup:

I hope this doesn't effect my status here hehehehehe:p

cunning-fox
06-26-2002, 01:48 AM
Hi,

The last code mentioned with the form did not work. I am sticking with this code below. But I need to use the first function on another page by itself, and still use the second function to check the window. Does anyone know how to correctly implement cookies to accomplish this, or is there a whole lot easier way I'm missing to do this (windows can have names, so I'm thinking why not just check the name with javascript, then let it determine where the page should go (second function) instead of creating all of these extra variables)? Can anyone come up with THE solution, so we can put this topic to rest.


<script language="JavaScript">
<!--

condition = '';

function createCondition() {

condition = window.open('condition.html', 'condition');
}

function condPopUp() {

if(condition && condition.open && ! condition.closed) {

success = window.open('success.html', 'success');

} else {

failure = window.open('login-required.html', 'failure');

}

}
//-->
</script>

glenngv
06-26-2002, 04:06 AM
I based my answer to your explanation below:


Originally posted by cunning-fox
Hi,

Once again thanks for all the replies.

I'm not sure that I explained everything so well, so I'll try to use more names.

A visitor goes to www.myaddress.com/index.html, they click and open a new window named www.myaddress.com/login.html and login. When they go to click on a basic link on my site, they open another window named www.myaddress.com/link.html, this page should check to see that the window- www.myaddress.com/login.html is present. If it is, then www.myaddress.com/link.com will be forwarded to www.yahoo.com. If not, then it will be forwarded to www.excite.com. Can anyone kind of recap on the last script to fit the above.

Much appreciation and thanks


in link.html:

if (window.opener && !window.opener.closed)
{ //login.html is still open
location.href="www.yahoo.com";
//use this instead if a new window should be opened:
//window.open("www.yahoo.com","Yahoo")
}
else
{ //login.html is closed
location.href="www.excite.com";
//use this instead if a new window should be opened:
//window.open("www.excite.com","Yahoo")
}

cunning-fox
06-27-2002, 04:33 AM
Thanks for the last reply, but that doesn't even include the relation with the login page,

Its still on the table, can anyone make this script workable somehow even when the second function is checking the page, when the first function opened the page? Or again, is there a definite way to send a user to a certain page based upon whether or not a certain window is open by using names. If you open a window named "login", couldn't you tell a page to open a certain page based on whether the window login is present using names? Not by defining variables.

Or if someone can somehow make this script work below by the second function being able to work separately on another page to check the conditions that the first function on another page created.

Thanks

glenngv
06-27-2002, 06:34 AM
in login.html:

<a href="link1.html" target="link1">Link1</a>
<a href="link2.html" target="link2">Link2</a>

or

<input type="button" value="Link1" onclick="window.open('link1.html','link1')">
<input type="button" value="Link2" onclick="window.open('link2.html','link2')">




in link1.html and link2.html:

if (window.opener && !window.opener.closed)
{ //login.html is still open
location.href="www.yahoo.com";
//use this instead if a new window should be opened:
//window.open("www.yahoo.com","Yahoo")
}
else
{ //login.html is closed
location.href="www.excite.com";
//use this instead if a new window should be opened:
//window.open("www.excite.com","Yahoo")
}


Originally posted by cunning-fox
Thanks for the last reply, but that doesn't even include the relation with the login page,

cunning-fox
06-27-2002, 07:57 PM
Thanks glen... for your reply. I see what you are suggesting. But with that code, it doesn't use names, it uses the page that opened another page (opener). You see, I have to use something like this function on other pages, not just the one that opened the pop-up as well:

function condPopUp() {

if(condition && condition.open && ! condition.closed) {

success = window.open('success.html', 'success');

} else {

failure = window.open('login-required.html', 'failure');

Thats why I was wondering if there was some definite way to use window names to tell the browser what to do, and therefore not restrict the code from only being able to check on one page. Is there any way to do this?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum