Location toolbar question

Posted on 2003-02-19
Medium Priority
Last Modified: 2010-04-09
Hello, I'm jbosch(vosk) and I would like to know if is there a way to get the location value,  and if is there a way to get the url from a iframe. Here is an example:
I have the main window with a textfield (or div, a, span, etc) named "A" and a iframe named "F". In the iframe there are some links to other pages or maybe a textfield named "B" and a button to open that new url. The user selects a link or enters a url and the iframe changes to the new url. What I want is display on the "A" textfield (or div, span,etc) from the main window that new url that the user has entered (maybe with a button, to get the new url). I have tryed with document.all.F.src but it always returns the predefined url.
That is the sample code to the main window:
<script language="JavaScript">
function veure()
var nova = document.all.F.src;
document.mainwindowform.A.value = nova;
<form name="mainwindowform">
Here I want to display the user-defined new url of the iframe:
<input type="text" name="A" value="" size="100">
<input type="button" name="B" value="URL" onClick="veure();">
<iframe id="F" src="firstiframepage.html" width="200" height="150">
And that is the same code for the iframe:
<form name="newurl">
<input type="text" name="B" value="">
<input type="button" name="C" value="new url" onClick="location = document.newurl.B.value">
I'm using MSIEv5.5
Question by:vosk
  • 2
LVL 17

Accepted Solution

dorward earned 80 total points
ID: 7980632

You could try document.all.F.document.location.href, but I expect that if the iframe has been sent to a different domain you will get failures (due to cross domain security features).

Author Comment

ID: 7980947
dorward: I have tryed with that but it returns the url of the predefined page used in the frame.
Do you know how I can get the value of a textfield placed in a iframe? I have tryed also that with document.all.F.document.formname.textfieldname.value but it returns an error.

Expert Comment

ID: 7983551
did you try:

document.frames(0).document.getElementById('elementid as string').value;

Author Comment

ID: 7987925
thomasdodds: I didn't try getElementById because I'm using MSIE, althought sometimes I use NSNv4.5, that version cannot use iframes.
Now I have read a cross-frame scripting and security and it tells the next:
window.location: property can be set to navigate, butc annot read.  
Other location: functionality is blocked.  
document.href: property can be set to navigate but cannot read.  
Other document: functionality is blocked.  
<IFRAME>: src property can be set to navigate but cannot read.
(and much more)
So I think that I can answer to myself saying that I cannot read a new url where an iframe has been redirected.
Thanks for both answers, but I'll give the points to dorward because was near to the right answer.

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

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

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
The first step to building an amazing About page is to figure out what you want the page to say about your company. You then must grab the attention of the reader, boast a bit, tell a story and let others brag about you. With a little bit of thought…
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …

616 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