|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
How do I get the URL of an iframe
if I use the getURL() command, i get the source of the current page, right?
Now I want to get the source of an iframe... can someone help me? thanks! |
|
#2
|
||||
|
||||
|
Here's an example I just wrote up to get/set the source of an IFRAME... It uses DOM...
Its may me complicated for what it's worth, but all you really need to do is one of the following: window.frames['my_frame_name'].src document.getElementById('my_frame_id').src Depends on your code... notice the difference between name and Id... My example uses the second example above... Code:
<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Changing IFRAME Src</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript">
<!--
function setSrc(obj, url) {
obj.src = url;
}
function getSrc(obj) {
alert(obj.src);
return obj.src;
}
//-->
</script>
</head>
<body>
<h1>Changing IFRAME src</h1>
<p><a href="#" onclick="javascript:setSrc(document.getElementById('myframe'),'new.htm ')">Change src</a> <b>|</b>
<a href="#" onclick="javascript:getSrc(document.getElementById('myframe'))">Get src</a></p>
<iframe id="myframe" src="old.htm"></iframe>
</body>
</html>
|
|
#3
|
|||
|
|||
|
hi,
Can you show me how to use the first example? When I use the second one (document.getElementById..), even after my page URL has change , the value is still old URL. I tyr to use frames[iframe_name].location.href; but i get permission denied. Please help. |
|
#4
|
|||
|
|||
|
I have exactly the same question. I have been able to get the original (old) src url with:
alert(document.getElementById('I1').src); but this does not change as visitors click on navigation links within the iframe. From another angle, the urls are present in the history array and available with back and forward, but can't seem to display the actual iframe url address text - must be a security thing (probably good). The iframe onload event does fire, but likewise, can't seem to get anything useful here. I don't like it, but I haven't seen any discussion that we can access the current url for an iframe. Wonder if this is a general issue with frames or just iframe. I'm going to try to do an example with frames instead of iframes and see if the same issue exists. Any one try this? |
|
#5
|
|||
|
|||
|
I'm also having this exact problem. Does anyone have a clue what I can do?
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > Programming Tools > How do I get the URL of an iframe |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|