Google Answers Logo
View Question
 
Q: Javascript ( Answered 5 out of 5 stars,   0 Comments )
Question  
Subject: Javascript
Category: Computers > Programming
Asked by: swykpisz-ga
List Price: $2.00
Posted: 01 Mar 2003 17:57 PST
Expires: 31 Mar 2003 17:57 PST
Question ID: 169401
How can I use a varaible or a result from a javascript with inline
frames,I want the page for the day to be displayed inside the
frame,here is what I'm using:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
<head> 
    <title>Sample: Your Daily Link</title> 
</head> 
<body> 
 
<h1>Sample: Your Daily Link</h1> 
 
<script type="text/javascript"><!-- 
 
var linkList = new Array(); 
var i = 1; 
var todaysLink = ""; 
var linkHtml = ""; 
var dateNow = new Date(); 
var dayOfMonth = dateNow.getDate(); 
 
linkList[i++] = "http://www.example.com"; 
linkList[i++] = "http://www.example.org"; 
linkList[i++] = "http://example.net"; 
linkList[i++] = "http://www.example.com"; 
linkList[i++] = "http://www.example.org"; 
linkList[i++] = "http://example.net"; 
linkList[i++] = "http://www.example.com"; 
linkList[i++] = "http://www.example.org"; 
linkList[i++] = "http://example.net"; 
linkList[i++] = "http://www.example.com"; 
linkList[i++] = "http://www.example.com"; 
linkList[i++] = "http://www.example.org"; 
linkList[i++] = "http://example.net"; 
linkList[i++] = "http://www.example.com"; 
linkList[i++] = "http://www.example.org"; 
linkList[i++] = "http://example.net"; 
linkList[i++] = "http://www.example.com"; 
linkList[i++] = "http://www.example.org"; 
linkList[i++] = "http://example.net"; 
linkList[i++] = "http://www.example.com"; 
linkList[i++] = "http://www.example.com"; 
linkList[i++] = "http://www.example.org"; 
linkList[i++] = "http://example.net"; 
linkList[i++] = "http://www.example.com"; 
linkList[i++] = "http://www.example.org"; 
linkList[i++] = "http://example.net"; 
linkList[i++] = "http://www.example.com"; 
linkList[i++] = "http://www.example.org"; 
linkList[i++] = "http://example.net"; 
linkList[i++] = "http://www.example.com"; 
linkList[i++] = "http://www.example.com"; 
 
todaysLink = linkList[dayOfMonth]; 
linkHtml += "<a href='" + todaysLink + "'>Today's link is " 
linkHtml += todaysLink + "</a> "; 
document.write(linkHtml); 
 
// --></script> 
 
</body> 
</html>

Request for Question Clarification by secret901-ga on 01 Mar 2003 19:26 PST
Hi swykpisz,
When you say "inline frame," do you mean those frames generated with
the keyword <IFRAME> or do you mean a normal frame (where pages are
not displayed on another)?
Answer  
Subject: Re: Javascript
Answered By: secret901-ga on 01 Mar 2003 19:42 PST
Rated:5 out of 5 stars
 
Hi swykpisz,
To make this script work with inline frames (whether generated by
<IFRAME> or a normal frame), all you have to do is to change one line
of your script:
Change this line:
linkHtml += "<a href='" + todaysLink + "'>Today's link is ";
to say:
linkHtml += "<a href='" + todaysLink + "'
target="NAME_OF_YOUR_FRAME_HERE">Today's link is ";

Here's a sample page I created that uses the IFRAME construct:

-----------------------------------------------------------------------
<html>
<head><title>My Page</title>
</head>
<body>
<a href="://www.google.com" target="googleanswers">Hi there</a>
<iframe src="http://answers.google.com" title="Google Answers"
name="googleanswers" scroll=auto></iframe>
</body>
</html>
-----------------------------------------------------------------------

I hope that answered your question.  If you still need clarification,
please don't hesitate to request for it.

secret901-ga

Search Strategy:
IFRAME

Request for Answer Clarification by swykpisz-ga on 01 Mar 2003 20:25 PST
I need to know what the source would be for the iframe from the
javascript if it generates a different link for each day. Is there any
working examples out there? Do iframes look in a directory then a
target? Any help would be greatly appreciated,thanks

Clarification of Answer by secret901-ga on 01 Mar 2003 21:15 PST
Hi swykpisz,
Here's an HTML for a working example of the script:
------------------------------------------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
"DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">  
<head>  
    <title>Sample: Your Daily Link</title>  
</head>  
<body>
<iframe src="http://answers.google.com" title="Google Answers"
name="googleanswers" scroll=auto></iframe>
  
<h1>Sample: Your Daily Link</h1>  
  
<script type="text/javascript"><!--  
  
var linkList = new Array();  
var i = 1;  
var todaysLink = "";  
var linkHtml = "";  
var dateNow = new Date();  
var dayOfMonth = dateNow.getDate();  
  
linkList[i++] = "http://www.day1.com";  
linkList[i++] = "http://www.day2.com";  
linkList[i++] = "http://www.day3.com";  
linkList[i++] = "http://www.day4.com";  
linkList[i++] = "http://www.day5.com";  
linkList[i++] = "http://www.day6.com";  
linkList[i++] = "http://www.day7.com";  
linkList[i++] = "http://www.day8.com";  
linkList[i++] = "http://www.day9.com";  
linkList[i++] = "http://www.day10.com";  
linkList[i++] = "http://www.day11.com";  
linkList[i++] = "http://www.day12.com";  
linkList[i++] = "http://www.day13.com";  
linkList[i++] = "http://www.day14.com";  
linkList[i++] = "http://www.day15.com";  
linkList[i++] = "http://www.day16.com";  
linkList[i++] = "http://www.day17.com";  
linkList[i++] = "http://www.day18.com";  
linkList[i++] = "http://www.day19.com";  
linkList[i++] = "http://www.day20.com";  
linkList[i++] = "http://www.day21.com";  
linkList[i++] = "http://www.day22.com";  
linkList[i++] = "http://www.day23.com";  
linkList[i++] = "http://www.day24.com";  
linkList[i++] = "http://www.day25.com";  
linkList[i++] = "http://www.day26.com";  
linkList[i++] = "http://www.day27.com";  
linkList[i++] = "http://www.day28.com";  
linkList[i++] = "http://www.day29.com";  
linkList[i++] = "http://www.day30.com";  
linkList[i++] = "http://www.day31.com";  
  
todaysLink = linkList[dayOfMonth];  
linkHtml += "Today's link is <a href='" + todaysLink + "'
target='googleanswers'>";
linkHtml += todaysLink + "</a> ";  
document.write(linkHtml);  
  
// --></script>  
  
</body>  
</html>
-------------------------------------------------------------

When you click on the link, it will change the page in the inline
frame so that it goes to the specified page.  You can find the page
here:
http://www.ics.uci.edu/~dhnguyen/test.htm

If you need further help, please provide me with the HTML source of
your current page and I'll be happy to assist you in adding a link
randomizer to it.

secret901-ga

Request for Answer Clarification by swykpisz-ga on 01 Mar 2003 21:38 PST
Right now the page is at
http://home.earthlink.net/~wykpisz/firstone.html
I'm trying to get the
http://home.earthlink.net/~wykpisz/just-trying.txt link to be display
inside the inline frame which would be correct for March 2nd but I get
an error,I don't need the hyperlink displayed just the page inside the
frame,the code is:
Hello Swykpisz, 
 
Use the following HTML page: 
 
--- 
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
<head> 
    <title>Sample: Your Daily Link</title> 
</head> 
<body> 
 
<h1>Sample: Your Daily Link</h1> 
 
<script type="text/javascript"><!-- 
 
var linkList = new Array(); 
var i = 1; 
var todaysLink = ""; 
var linkHtml = ""; 
var dateNow = new Date(); 
var dayOfMonth = dateNow.getDate(); 
 
linkList[i++] = "http://www.example.com"; 
linkList[i++] = "http://home.earthlink.net/~wykpisz/just-trying.txt";
linkList[i++] = "http://example.net"; 
linkList[i++] = "http://www.example.com"; 
linkList[i++] = "http://www.example.org"; 
linkList[i++] = "http://example.net"; 
linkList[i++] = "http://www.example.com"; 
linkList[i++] = "http://www.example.org"; 
linkList[i++] = "http://example.net"; 
linkList[i++] = "http://www.example.com"; 
linkList[i++] = "http://www.example.com"; 
linkList[i++] = "http://www.example.org"; 
linkList[i++] = "http://example.net"; 
linkList[i++] = "http://www.example.com"; 
linkList[i++] = "http://www.example.org"; 
linkList[i++] = "http://example.net"; 
linkList[i++] = "http://www.example.com"; 
linkList[i++] = "http://www.example.org"; 
linkList[i++] = "http://example.net"; 
linkList[i++] = "http://www.example.com"; 
linkList[i++] = "http://www.example.com"; 
linkList[i++] = "http://www.example.org"; 
linkList[i++] = "http://example.net"; 
linkList[i++] = "http://www.example.com"; 
linkList[i++] = "http://www.example.org"; 
linkList[i++] = "http://example.net"; 
linkList[i++] = "http://www.example.com"; 
linkList[i++] = "http://www.example.org"; 
linkList[i++] = "http://example.net"; 
linkList[i++] = "http://www.example.com"; 
linkList[i++] = "http://www.example.com"; 
 
todaysLink = linkList[dayOfMonth]; 
linkHtml += "<a href='" + todaysLink + "'>Today's link is " 
linkHtml += todaysLink + "</a> "; 
document.write(linkHtml); 
 
// --></script> 

<div align="center">
                  <center>
                  <table border="1" cellpadding="0" cellspacing="0"
style="border-collapse: collapse" bordercolor="#808080" width="241">
                  
                    <tr>
                <td height="30" background="images/bkgrnd.gif"
width="100%" align="left" valign="bottom">
            
                <a href="newsframe.htm" target="news">
                <img border="0" src="local_tab.gif" alt="Local News"
width="76" height="25"></a></td>
                    </tr>
                    <tr>
                <td height="143" bgcolor="#FFFFFF" valign="top"
align="center">
            
                <table border="0" cellpadding="3" cellspacing="0"
style="border-collapse: collapse" bordercolor="#111111" width="100%"
id="AutoNumber6">
                  <tr>
                    <td width="100%">
            
                <iframe name="news" border="0" frameborder="0"
width="100%" height="252" src="newsframe.htm" align="top"
target="_top">
                Your browser does not support inline frames or is
currently configured not to display inline frames.</iframe>
            
                      </td>


 
</body> 
</html>

Clarification of Answer by secret901-ga on 01 Mar 2003 21:50 PST
Hi swykpisz,
I have updated the page http://www.ics.uci.edu/~dhnguyen/test.htm so
that it looks like your page.  Your inline frame is called "news," so
I used it as the target of the links.  I changed my calendar to read
March 2 (it's still March 1 here) and then opened the page. Your test
page correctly popped up into the IFRAME.

I hope this answered my question, if you are still confused, please
request for a clarification before rating this answer.

secret901-ga

Request for Answer Clarification by swykpisz-ga on 01 Mar 2003 22:00 PST
I appreciate your patience on this subject but how do I get the link
of the day to be displayed in the inline frame? I get an error saying
the source file is not located no matter what I name the iframe name.
Is it possible to have the source file to be different each day?

Clarification of Answer by secret901-ga on 01 Mar 2003 22:12 PST
Hi swykpisz,
I think I understand what you want.  Is what you really want is for
the IFRAME to show the linked page immediately when the page loads,
without the intervention of the user?  Currently, the IFRAME will NOT
load your linked page until the user clicks on the link.  Please tell
me if this is the case.

secret901-ga

Clarification of Answer by secret901-ga on 01 Mar 2003 22:31 PST
Hi swykpisz,
Below is another version of the page that sets the IFRAME to the
linked page without user intervention.  Please tell me if this is what
you want.
http://www.ics.uci.edu/~dhnguyen/test2.htm
swykpisz-ga rated this answer:5 out of 5 stars and gave an additional tip of: $2.00
I appreciate the patience and the research taken to answer this
question. This will help with my understanding in the future,thank you
very much

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy