Solved

Displaying a new url onclick

Posted on 2003-11-17
7
3,848 Views
Last Modified: 2008-02-01
Sorry, I forgot this one.

I want to display a new web page when I click on a button.

Something like:

onClick='javascript:url( "theWebPageIWant")'

0
Comment
Question by:rfr1tz
7 Comments
 
LVL 19

Assisted Solution

by:Dexstar
Dexstar earned 50 total points
ID: 9766198
rfr1tz:

> onClick='javascript:url( "theWebPageIWant")'

Try this:
     onclick='javascript:document.location.href="theWebPageIWant"';

Hope That Helps,
Dex*
0
 
LVL 16

Assisted Solution

by:jaysolomon
jaysolomon earned 50 total points
ID: 9766415
<a href="theWebPageIWant" onclick="location.href = this.href;return false">Go</a>

1 you do not need the javascript: protocol since onclick is part of JS.

2 if you do it this away, even javascript disabled browsers will be able to go to that page also.
0
 
LVL 7

Expert Comment

by:wsteegmans
ID: 9766454
You could also create an new JavaScript Function, like this one ..

function OpenNewWindow(url, wWidth, wHeight)
{      var wTop      = 0
      var wLeft      = 0
      var openProps
      
      if (screen)
      {            
                  wLeft      = (screen.width  / 2) - (wWidth / 2)
                  wTop      = (screen.height / 2) - (wHeight / 2)
      }
      openProps = "width="+wWidth+",height="+wHeight+",left="+wLeft+",top="+wTop;
      return window.open(url,"win",openProps,'location=no, menubar=no, toolbar=no')

}

This function has three parameters, the url, the width and the heigth. An example of calling this function is (in your case):
  onclick="javascript:OpenNewWindow('http://www.experts-exchange.com', 800,600);"
This function opens a new window (nice centered on the screen) without addressbar, buttons, ... So, try it out ...

For more info about the window.open statement:
http://www.devguru.com/technologies/ecmascript/quickref/win_open.html
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 17

Expert Comment

by:dorward
ID: 9767663
0
 
LVL 2

Accepted Solution

by:
incongruent earned 150 total points
ID: 9769420
to give you exactly what you asked for:

<input type=button name=cmdButton value="Click Me" onClick="document.location.href='theWebPageIWant.html';">


or if you want it to open in a popup window:

<input type=button name=cmdButton value="Click Me"
onClick="window.open('theWebPageIWant.html','','width=500,toolbar=yes,height=500,status=yes');">

-Cheers,

Allan
0
 
LVL 11

Expert Comment

by:Zontar
ID: 9769969
document.locaiton is supposed to be read-only and won't work being set in some browsers. Use window.locaiton.
0
 
LVL 1

Expert Comment

by:umangjoshi
ID: 9770808
just try this

<input type="button" name="btn1" value="Click Here" onClick="location.href = 'xyz.html'; ">
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
HTML Video won't Autoplay on site 6 22
PHP email variable syntax 3 44
css border raidius issue 7 74
SP to delete duplicates 15 55
Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn how to count occurrences of each item in an array.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now