473,387 Members | 1,611 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

URL to iFrame

118 100+
Hi all,

I have a site that I'm making for a project.

I have an Input field, a button and an iFrame.

What I would like to do is have the user type in a URL into the input field, press the button and then the browser shows the resulting webpage into the iFrame.

What Javascript would I need for this? Any ideas?
Sep 21 '07 #1
3 1251
pbmods
5,821 Expert 4TB
Heya, Helraizer.

You'd access the text in the textbox like this:
Expand|Select|Wrap|Line Numbers
  1. var url = document.getElementById('idOfTextbox').value;
  2.  
And to navigate in the iframe:
Expand|Select|Wrap|Line Numbers
  1. document.getElementById('idOfIframe').location.href = url;
  2.  
Sep 21 '07 #2
helraizer1
118 100+
Thank you! That worked. =)

Now the problem is validation. If the user types in www.bbc.co.uk - it won't work because there is no http:// so I added

Expand|Select|Wrap|Line Numbers
  1.  
  2.         document.getElementById('myiFrame').src = "http://" + url;
  3.  
Which then works if the only type in a www. address. If they do type in 'http://www.bbc.co.uk' then the resulting site is 'http://http://www.bbc.co.uk and thus does not work.

How would I impliment it so that if they only put 'www.bbc.co.uk' it adds the 'http://' infront but if they do add 'http://' then it doesn't.

Hope I made myself understandable there. Any ideas?

Thanks,

Sam
Sep 22 '07 #3
pbmods
5,821 Expert 4TB
Heya, Sam.

You'll want to use String::indexOf() for that:
Expand|Select|Wrap|Line Numbers
  1. if( url.indexOf('http://') != 0 )
  2. {
  3.  
Note that the code above checks to see if the result of url.indexOf() is not 0. String::indexOf() will return -1 if the search value is not found, but it is conceivable that the User might put in a badly-formed query string, so you want to make sure that the string doesn't start with 'http://'.

For example, suppose the User input something like this:
Expand|Select|Wrap|Line Numbers
  1. www.myphpproxy.tld/path/to/proxy.php?url=http://www.google.com/
  2.  
There is a 'http://' in this string, but of course it's not a valid URL.
Sep 22 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Csaba2000 | last post by:
I want to be able to embed a single quote into an INPUT element within a dynamically generated IFRAME. The example below shows how the IFRAME is generated. Challenge: I'd like the alert box to...
4
by: Thomas | last post by:
Hi there, I have an iframe which is editable (designMode = "on") and want to resize it dynamically as the content grows (e.g. more lines of text is in there) and there the struggle starts. I...
2
by: Templar | last post by:
Hi i'm bothering with such problem... I must dynamic create an Iframe, and then put som raw HTML into it. But I can't. When I create iframe, I can't access its properties. Here's the coe...
1
by: Martin | last post by:
There seems to be some strange behaviour when trying to get the scrollHeight and scrollTop of an iframe in IE6. I have tried several ways of getting these values when the iframe is written into...
7
by: Christopher J. Hahn | last post by:
I'm trying to use a script-generated form to submit to a script-generated iframe. The problem I'm running into is that the iframe is not assuming the name I assign it. IE6 on Win2000. FF1.0.2+...
3
by: Angel | last post by:
How do I get the reference of the IFrame from the asp.net webpage that is being displayed within that IFrame? In other words I have an IFrame in my page. Within that IFrame Set the source to a...
0
by: tequilamala | last post by:
I have an Iframe in one of the pages i am developing... the iframe is suppose to scroll up and down and the links target the iframe. the problem is that the iframe scrolls side to side on internet...
1
by: Z1P2 | last post by:
I would like to gradually resize an iframe in an onmouseover event. I can easily do it with an image, but when I try to do it with an iframe, it doesn't do anything. So first of all, is it possible...
1
by: cdmsenthil | last post by:
I have an Infragistics UltrawebGrid . Each Row in the grid is attached to a context menu using Infragistics CSOM Upon click on the menu, I am creating an Iframe dynamically which points to...
23
by: vunet | last post by:
It is recommended by some sources I found to create IFrames in IE using document.createElement('<iframe src="#">') instead of document.createElement('iframe'). Why and what browser versions to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.