[SOLVED] Link to another page in JavaScript

This is a discussion on "[SOLVED] Link to another page in JavaScript" within the JavaScript Forum section. This forum, and the thread "[SOLVED] Link to another page in JavaScript are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Jan 28th, 2008, 15:18
Reputable Member
Join Date: May 2007
Location: Margate
Age: 24
Posts: 156
Thanks: 0
Thanked 0 Times in 0 Posts
[SOLVED] Link to another page in JavaScript

How do you put a link within JAVA

I am after linking .../page1/index.html to page1 below and similar to page2


Code: Select all
 
var before="page1"
var current="page2"
Cheers

Dan
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Jan 28th, 2008, 15:40
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
Re: Link to another page in JAVA

JAVA or JavaScript?
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Jan 28th, 2008, 15:41
Reputable Member
Join Date: May 2007
Location: Margate
Age: 24
Posts: 156
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Link to another page in JAVA

javascript, can supply all script if req
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Jan 28th, 2008, 15:47
Marc's Avatar
Staff Manager

SuperMember
Join Date: Apr 2007
Location: Scotland, UK
Posts: 1,775
Thanks: 0
Thanked 14 Times in 14 Posts
Re: Link to another page in JavaScript

Changed title so it says "JavaScript" instead of "JAVA".
__________________
Marc
Staff Manager - Webforumz.com


Want to be a moderator? PM me.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Jan 28th, 2008, 15:53
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
Re: Link to another page in JavaScript

Not really sure how you want to link the pages.
Post your script and explain a little clearer for a better answer.
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old Jan 28th, 2008, 15:58
Reputable Member
Join Date: May 2007
Location: Margate
Age: 24
Posts: 156
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Link to another page in JavaScript

Code: Select all
 
<script>
//change the text below to reflect your own,
var before="Update required"
var current="Update is now required"
var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
function countdown(yr,m,d){
var today=new Date()
var todayy=today.getYear()
if (todayy < 1000)
todayy+=1900
var todaym=today.getMonth()
var todayd=today.getDate()
var todaystring=montharray[todaym]+" "+todayd+", "+todayy
var futurestring=montharray[m-1]+" "+d+", "+yr
var difference=(Math.round((Date.parse(futurestring)-Date.parse(todaystring))/(24*60*60*1000))*1)
if (difference==0)
document.write(current)
else if (difference>0)
document.write("Only "+difference+" days until "+before)
}
//enter the count down date using the format year/month/day
countdown(200,2,14)
</script>
var before="Update required" (when Update required is shown it is a link to a another page)
var current="Update is now required" (when Update is now required is shown it is a link to a another page)

the above text to be links "update required" one link then when time runs out the "update is now required" required another link.


Does that make a little more sence

Last edited by R8515198; Jan 29th, 2008 at 07:24.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7  
Old Jan 28th, 2008, 16:32
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Link to another page in JavaScript

When you want to change the current page with javascript you just change the windows loacation..

Code: Select all
// I want to go to google

window.location.href = 'http://www.google.com';
The links will work with relative URLS as well so

window.location.href = 'page.html';

Will work just as well.

In you script if you need to change the page based on some even you just set the variables before and current to the URL's you want and change the page like

Code: Select all
if (something == 'nothing')
   location.href = before;
else
   location.href = current;
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8  
Old Jan 29th, 2008, 07:38
Reputable Member
Join Date: May 2007
Location: Margate
Age: 24
Posts: 156
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Link to another page in JavaScript

Cant get it to work.

var before="Update required"

var current="Update is now required"

If we say the URLs are: (before)yahoo.com and (current)google.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #9  
Old Jan 29th, 2008, 08:46
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Link to another page in JavaScript

If you're linking to another domain you need to include the whole URL.. eg protocol/server/path/query

var before = 'http://www.yahoo.com';
var current = 'http://www.google.com';
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #10  
Old Jan 29th, 2008, 08:49
Reputable Member
Join Date: May 2007
Location: Margate
Age: 24
Posts: 156
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Link to another page in JavaScript

When I do the above it just shows the URL and it is not a link?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #11  
Old Jan 29th, 2008, 09:30
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Link to another page in JavaScript

Oh!.. You don't want to send the page to a different URL, you actuall want to write an <a></a> link to the page... I misunderstood.

You would just need to change

var before = '<a href="http://www.yahoo.com">Yahoo.com</a>';
var current = '<a href="http://www.google.com">Google.com</a>';
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #12  
Old Jan 29th, 2008, 10:29
Reputable Member
Join Date: May 2007
Location: Margate
Age: 24
Posts: 156
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Link to another page in JavaScript

You are a genius,

That has just completed a very big part of my project, when looking at it - it was simple but when you stare at hte code for so long ur mind goes blank.


I appriciate the help RAKULI, I owe you a beer.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #13  
Old Jan 30th, 2008, 18:08
Ed Ed is online now
Moderator
Join Date: Jul 2007
Location: Cork, Ireland
Posts: 730
Blog Entries: 1
Thanks: 0
Thanked 1 Time in 1 Post
Re: [SOLVED] Link to another page in JavaScript

That doesn't look like the quality beer Rakuli would be after!

lol

Ed.
Last Blog Entry: Happy New Year! (Dec 31st, 2007)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Making a link non-link when on the page. mcdanielnc89 Web Page Design 1 Nov 16th, 2007 08:05
[Tutorial -> Trick] Link checking using JavaScript (ny myself) RohanShenoy JavaScript Forum 7 Nov 8th, 2007 12:52
[SOLVED] Javascript Printer-Friendly Page &quot;Creator&quot; Stuart JavaScript Forum 33 Oct 13th, 2007 13:06
how to link a php page to the designed page s_mazhar PHP Forum 3 Dec 28th, 2005 05:21
Can you link in .asp files like you can .css and Javascript? Andy K Classic ASP 2 Jul 13th, 2005 10:13


All times are GMT. The time now is 18:43.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42