Current location: Hot Scripts Forums » General Web Coding » JavaScript » Display URL of iFrame

Display URL of iFrame

Reply
  #1 (permalink)  
Old
Newbie Coder
 
Join Date: Oct 2007
Location: London, UK
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Question Display URL of iFrame

Hi,

I would like to display the URL of a frame in an INPUT box... Is this possible?

I've got as far as finding this script that displays the URL in an alert box, but I'd like it in an input box...?

Thanks
Reply With Quote

Featured Marketplace Scripts (view more)

  #2 (permalink)  
Old
Nico's Avatar
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,129
Thanks: 12
Thanked 93 Times in 89 Posts
Topic moved to Javascript.
Reply With Quote
  #3 (permalink)  
Old
Vicious's Avatar
Community VIP
 
Join Date: Jan 2007
Location: Belgium
Posts: 584
Thanks: 0
Thanked 0 Times in 0 Posts
Assuming that you have the url of the iframe, I'll continue from there.

Firstly, give your input box (again, assuming that you mean <input type="text" />) an ID, and then use the code below to fill the url into that input box.

javascript Code:
  1. // above is the code to get the url from your frame
  2.  
  3. // now we place that url into the input box:
  4. document.getElementById("the_id_of_my_input_box").value = frameURL; // with frameURL defined earlier
  5.  
__________________
Jack Bauer makes Chuck Norris cry
Reply With Quote
  #4 (permalink)  
Old
Newbie Coder
 
Join Date: Oct 2007
Location: London, UK
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Exclamation

I've been trying to implement what you suggested, Vicious... but I can't seem to get it to work

Here's what I've got:

HTML Code:
<html>
<head>
<script type="text/javascript">
<!--
function setSrc(obj, url) {
	obj.src = url;
}

function getSrc(obj) {
	alert(obj.src);
	return obj.src;
}
//-->
// above is the code to get the url from your frame

// now we place that url into the input box:
document.getElementById("frameid").value = myframe; // with frameURL defined earlier 
</script>
</head>
<body>
<p><b>|</b> 
<a href="#" onclick="javascript:getSrc(document.getElementById('myframe'))">Get src</a> - displays with alert</p>

<iframe id="myframe" src="http://www.google.com"></iframe>
<br>
<br>
<input Id="frameid"><p>frameurl not showing in input</p>
</body>
</html>
Thanks,
ftvids
Reply With Quote
  #5 (permalink)  
Old
Vicious's Avatar
Community VIP
 
Join Date: Jan 2007
Location: Belgium
Posts: 584
Thanks: 0
Thanked 0 Times in 0 Posts
I modified your code, and tested it in Firefox:

HTML Code:
<html>
<head>
<script type="text/javascript">
<!--
function setSrc(obj, url) {
	obj.src = url;
}

function getSrc() {
	var obj = document.getElementById('myframe');
	document.getElementById("frameid").value = obj.src;
	return false; // if we return false, then we don't go to the URL defined in the href (here #)
}
//-->
</script>
</head>
<body>
<p><b>|</b> 
<a href="#" onclick="return getSrc();">Get src</a> - displays with alert</p>

<iframe id="myframe" src="http://www.google.com"></iframe>
<br>
<br>
<input id="frameid" value="" name="frameid" /><p>frameurl not showing in input</p>
</body>
</html>
__________________
Jack Bauer makes Chuck Norris cry

Last edited by wirehopper; 07-21-09 at 03:02 PM. Reason: HTML tags
Reply With Quote
  #6 (permalink)  
Old
New Member
 
Join Date: Jul 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Question Open URL instead of showing in the box ?

Hello,

is it possible to open the iframe URL instead of viewing it in the text box ? And if yes, how

Im not able to get that.

Thanks in advance.
Reply With Quote
  #7 (permalink)  
Old
wirehopper's Avatar
-
 
Join Date: Feb 2006
Posts: 2,515
Thanks: 20
Thanked 110 Times in 107 Posts
I'm not sure if I understand the question - this code will redirect the page to the new URL.

Code:
location.href='http://domain.com/url';
You could also use window.open HTML DOM open() Method
Reply With Quote
  #8 (permalink)  
Old
New Member
 
Join Date: Jul 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by wirehopper View Post
I'm not sure if I understand the question - this code will redirect the page to the new URL.

Code:
location.href='http://domain.com/url';
You could also use window.open HTML DOM open() Method
Hi,

thanks for your answer. And sorry for the late reply I think I thought i would never get an answer hehe. Problem is right now that i dont know anymore why I needed it this way :-/ Or how exactly i ment it..
I think i tried to get a WordPress form via an iFrame but it didnt worked so well or as i wanted and i couldnt use 'include'. Hm well gonna have to check that again
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Parent window URL from Iframe scotty69 JavaScript 1 01-04-08 10:58 PM
OnClick Iframe URL changes? eq1987 JavaScript 2 09-26-04 01:49 PM
Image display based on URL rjwebgraphix PHP 5 09-09-04 08:02 AM
iframe linking not working under url masking willNoClue HTML/XHTML/XML 1 08-02-04 10:34 AM


All times are GMT -5. The time now is 12:35 AM.
vBulletin® Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.