Solved

display new page after image is loaded

Posted on 2009-05-07
11
215 Views
Last Modified: 2012-05-06
I've followed this example from Tech Republic.  However, I need to know how to assign a more complicated anchor tag to the document.location.href object.

Instead of index2.html, as shown in the example below, I have the following anchor tag:
<a href='<%=formattedURL.toString()%>' target='_blank'><img align="center" border="0" src="<render:getSkinPath imageName="button.gif"/>"/></a>&nbsp;

How do I assign all of this to the document object?

<html>
 
<head>
 
<script language="JavaScript">
 
 
 
// create an image object
 
objImage = new Image();
     
 
// set what happens once the image has loaded objImage.onLoad=imagesLoaded();
     
 
// preload the image file
 
objImage.src='images/image1n.gif';
 
 
 
// function invoked on image load
 
function imagesLoaded()
 
{    
     document.location.href='index2.html';
 
}
 
 
 
</script>
 
</head>

Open in new window

0
Comment
Question by:newbieal
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 3
11 Comments
 
LVL 4

Expert Comment

by:Ronb23
ID: 24329382
If I understand this correctly, you're looking to pass a different URL into your function.

Try this in your JavaScript function:

function imagesLoaded()
{
      var myURL = '<%=formattedURL.toString()%>';
      document.location.href='myURL';
}

and you href tag would look something like this:
<a href="#" onClick="javascript:imagesLoaded();" target='_blank'><img align="center" border="0" src="<render:getSkinPath imageName="button.gif"/>"/></a>

hope this helps.
0
 
LVL 4

Author Comment

by:newbieal
ID: 24335824
Looks good, but when I implement this code, instead of opening up a new window with it pointing to myURL, it just opens up a new window with the previous screen.  I'm thinking it's the href="#" part.
shouldn't it be href="myURL"?
0
 
LVL 4

Expert Comment

by:Ronb23
ID: 24336847
document.location.href is a control for the current window you're in. Also, if you placed "myURL" in the href="#", that defeats the purpose of assigning the javascript funtion with the url. You could also try this:

function imagesLoaded()
{
      var myURL = '<%=formattedURL.toString()%>';
      window.open='myURL';
}

<a href="#" onclick="imagesLoaded();return false;">><img align="center" border="0" src="<render:getSkinPath imageName="button.gif"/>"/></a>
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Author Comment

by:newbieal
ID: 24337106
i would like to open a new window though.  How do i do this?
0
 
LVL 4

Expert Comment

by:Ronb23
ID: 24337154
What i posted above opens a new window.
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 24337172
To open a new window you need to use ...
function imagesLoaded() {
    var myUrl = '<%=formattedURL.toString()%>';
    window.open(myUrl, 'newWindow');
}
Window.open doesn't use an equal sign.  Let me know if there is a question.
bol
0
 
LVL 54

Assisted Solution

by:b0lsc0tt
b0lsc0tt earned 200 total points
ID: 24337210
Take a look at the html source (i.e. in the browser choose the View Source option) to see how  the resulting html looks.  It seems you may end up with extra > characters.  Post that code if you have a question or still have a problem getting this to work.
bol
0
 
LVL 4

Expert Comment

by:Ronb23
ID: 24337290
oops sorry, pasted the wrong one:

function imagesLoaded()
{
      var myURL = '<%=formattedURL.toString()%>';
      window.open(myURL)';
}

<a href="#" onclick="imagesLoaded();return false;">><img align="center" border="0" src="<render:getSkinPath imageName="button.gif"/>"/></a>
0
 
LVL 54

Assisted Solution

by:b0lsc0tt
b0lsc0tt earned 200 total points
ID: 24337562
>>       window.open(myURL)'; <<

You need to include the second parameter when using window.open.  It is for the "name" of the window and is not optional.  Leaving it off might work in some browsers but will fail and it should not be omitted.
bol
p.s.  There is also a typo in that line
0
 
LVL 4

Accepted Solution

by:
Ronb23 earned 300 total points
ID: 24337631
Having a sloppy day. It's the Friday syndrome...

function imagesLoaded()
{
      var myURL = '<%=formattedURL.toString()%>';
      window.open(myURL, 'newwin');
}

<a href="#" onclick="imagesLoaded();return false;">
<img align="center" border="0" src="<render:getSkinPath imageName='button.gif'/>"/>
</a>
0
 
LVL 4

Author Closing Comment

by:newbieal
ID: 31579135
worked, thanks much!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Video Tutorial help 2 38
Glitching Slide Show 19 27
Calculating percentage 2 29
How do I post more than 1 item to php backend 24 30
Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

756 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