A Digital Age Deserves A Digital Leader

Javascript redirect into a frame

Javascript redirect into a frame

Postby gries818 » Wed Aug 13, 2008 2:41 pm

Is it possible to redirect to a new page in another frame? With straight up HTML tags it's easy:

Code: Select all
<a href="index.html" target="frm_main">title here</a>


However I need to use Javascript to have this same effect because I'm building a query string on an asp file (ie default.asp?id=1) with Javascript and then want to send it along without making a link which I prompt the user to click. :lol:
Image

Mac OS 10.6.7 - Personal
Ubuntu Server 11.04 - Server
Software Development
User avatar
Posts: 3991
Joined: Wed Jul 07, 2004 6:28 pm

Postby gries818 » Wed Aug 13, 2008 3:01 pm

I forgot to mention that I need to redirect into an iframe.
Image

Mac OS 10.6.7 - Personal
Ubuntu Server 11.04 - Server
Software Development
User avatar
Posts: 3991
Joined: Wed Jul 07, 2004 6:28 pm

Postby jbullard » Wed Aug 13, 2008 6:03 pm

Javascript is pretty straightforward as well.

Code: Select all
top.frames['myframe'].location.href = 'index.htm';


What I would do is something like this

Code: Select all
<head>

<script type="text/javascript">
function open_in_frame(FrameName, FrameURL)
{
top.frames[FrameName].location.href = FrameURL;
}
</script>

</head>



That way you can use it many times without having to change any code.
VP - Software
User avatar
Posts: 3653
Joined: Sun Jun 06, 2004 10:17 pm
Location: Utah
Real Name: Jason Bullard

Postby gries818 » Wed Aug 13, 2008 6:04 pm

Ok the solution to this one is so easy it actually makes me embarrassed lol. The key is to treat the iframe like any other object on the page and just use:

Code: Select all
document.getElementById('frm_main').src = "test.asp";
Image

Mac OS 10.6.7 - Personal
Ubuntu Server 11.04 - Server
Software Development
User avatar
Posts: 3991
Joined: Wed Jul 07, 2004 6:28 pm

Return to HTML, CSS, and Scripts

Who is online

Users browsing this forum: No registered users and 0 guests