By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,817 Members | 2,152 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,817 IT Pros & Developers. It's quick & easy.

Trouble with IFRAME & Javascript

P: n/a
I am trying to be able to pass a parameter in my URL to a subpage that
will load the file specified in the paramater into an IFRAME. I have
hardly used Javascript, and am trying to figure out how I would do
this. My URL should always look like this:

http://www.xxx.com/newsite/subpage.h...=filename.html

The javascript I came up with looks like this, because I will only have
one parameter and I know that with the ? and the = that the length of
the param name will always be 6.:

<SCRIPT language="JavaScript" type="text/javascript">

function GetDocName() {
var
SearchStr, // Search String
DocName, // Name of Document to Use
NameLen; // Length of Document Name

SearchStr = location.search;
NameLen = SearchStr.Length;
DocName = "documents/"+SearchStr.Substring(7,NameLen);
}
return DocName;

</SCRIPT>
What I don't know is how to get the results of the function into my
Iframe. This is what I have tried, with no luck:
<IFRAME height="600" width="780" scrolling="auto"
src="javascript:parent.GetDocName()"></IFRAME>
Any help with this would greatly be appreciated!

Ralph

Sep 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
ASM
webguru wrote:
I am trying to be able to pass a parameter in my URL to a subpage that
will load the file specified in the paramater into an IFRAME. I have
hardly used Javascript, and am trying to figure out how I would do
this. My URL should always look like this:

http://www.xxx.com/newsite/subpage.h...=filename.html

The javascript I came up with looks like this, because I will only have
one parameter and I know that with the ? and the = that the length of
the param name will always be 6.:

<SCRIPT language="JavaScript" type="text/javascript">

function GetDocName() {
var
SearchStr, // Search String
DocName, // Name of Document to Use
NameLen; // Length of Document Name

SearchStr = location.search;
NameLen = SearchStr.Length;
DocName = "documents/"+SearchStr.Substring(7,NameLen);
}
return DocName;

</SCRIPT>
What I don't know is how to get the results of the function into my
Iframe. This is what I have tried, with no luck:
<IFRAME height="600" width="780" scrolling="auto"
src="javascript:parent.GetDocName()"></IFRAME>


document.write('<IFRAME height="600" width="780" scrolling="auto" '+
'src="'+GetDocName()+'"><\/IFRAME>');

or

<body onload="parent.myIframe.location = GetDocName();">

--
Stephane Moriaux et son [moins] vieux Mac
Sep 21 '05 #2

P: n/a
webguru <ra**********@hotmail.com> wrote in message news:11*********************@g14g2000cwa.googlegro ups.com...
NameLen = SearchStr.Length;
should be SearchStr.length;
DocName = "documents/"+SearchStr.Substring(7,NameLen);
'Substring' should be 'substring' and the offset should be 6.

There's little point in assigning variables that are only to be referenced once,
so you could reduce the function to:

function GetDocName()
{
return "documents/"+location.search.substring(6, location.search.length);
}

or to make it independent of the length of the parameter:

function GetDocName()
{
var ls = location.search;

return "documents/"+ls.substring(ls.lastIndexOf('=')+1, ls.length);
}
What I don't know is how to get the results of the function into my
Iframe. This is what I have tried, with no luck:


You've been shown that so I won't repeat it.

--
Sep 21 '05 #3

P: n/a
Thank you both for your input. It works exactly like I wanted it to
now! I really appreciate it.

Sep 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.