|
-
Aug 21st, 2012, 12:03 AM
#1
Thread Starter
Addicted Member
[RESOLVED] Set Text in textbox within an iframe
I have been struggling with this for quite some time and just cannot work this out. I am trying to set text within a textbox that is within an iframe which has no name. I tried several different methods to access the textbox element called "element_2_1" but I haven't had any luck. I am able to identify the frame using GetElementsByTagName and looking for the title of the frame (see code below) but that is as far as I have been able to go. I would greatly appreciate any help I can get on this.
Snippet of iframe Source:
<p><iframe height="2981" allowTransparency="true" frameborder="0" scrolling="no"
style="width:90%;border:none" src="http://someurl.com/someform/embed.php?id=2"
title="This is some page title - example page title!"><a
href="http://someurl.com/someform/view.php?id=2" title="This is some page title - example page title!" onclick="pageTracker._trackPageview('/outgoing/someurl.com/someform/view.php?id=2&referer=http%3A%2F%some.referer.com%2Fhub%2Fs');">This is some page title - example page title!</a></iframe></p>
iframe's Textbox Source:
<input id="element_2_1" name="element_2_1" type="text" class="element text" maxlength="255" size="8" value=""
VB.NET Code:
Dim hec As HtmlElementCollection = WB1.Document.GetElementsByTagName("iframe")
On error resume next
If ele.GetAttribute("title") = "This is some page title - example page title!" Then
Msgbox "Found!"
'ele.Document.All("element_2_1").InnerHtml = "test" '//Tried this without success
End If
Next
-
Aug 21st, 2012, 12:12 PM
#2
Thread Starter
Addicted Member
Re: Set Text in textbox within an iframe
Anyone have any suggestions?
-
Aug 25th, 2012, 12:19 PM
#3
Thread Starter
Addicted Member
Re: Set Text in textbox within an iframe
Just a quick update, I still have not found an answer to this, I'd appreciate any suggestions that anyone might have.
-
Aug 25th, 2012, 12:22 PM
#4
Re: Set Text in textbox within an iframe
Perhaps if you were a little less coy about the identity of the webpage in question we could do some investigating?
-
Aug 25th, 2012, 01:25 PM
#5
Thread Starter
Addicted Member
Re: Set Text in textbox within an iframe
I am working with a rather unique concept and I am required to guard the details as much as possible. I was hoping that the example HTML code above which mirrors the HTML/iFrame code that I am working with would help illustrate what I am working with. I am not looking for someone to provide exactly working code specific to that site, just suggestions or an example of what may work.
-
Aug 25th, 2012, 04:44 PM
#6
Re: Set Text in textbox within an iframe
The fact is that programming for web interaction is almost never possible without knowing the quirks of the site that one is dealing with. The only general procedure I can recommend is that you don't attempt this in an iframe. If you can load the iframe content as a separate document, manipulate it there and then return it to the iframe that's the only possible route I can suggest without further specifics. But looking at what you have deigned to reveal I'm far from sure that's going to be possible.
I am working with a rather unique concept and I am required to guard the details as much as possible.
Yes well, with all due respect, that's what they all say! Very rarely does it prove to be the case that anything is unique or that anybody is 'required' to keep it all secret (unless they're working for the mob!) One thing I do know. There's nothing unique about a project that doesn't work because the programmer doesn't have the necessary skill and is too self absorbed to ask for help. Anyway, I think you can safely assume you've exhausted the extent of any help (to say nothing of the patience) of those of us here so please do not bump this thread again.
-
Aug 25th, 2012, 10:22 PM
#7
Thread Starter
Addicted Member
Re: Set Text in textbox within an iframe
-Editted Out-
God is good.
Last edited by SavedByGrace; Aug 25th, 2012 at 10:33 PM.
-
Aug 25th, 2012, 10:38 PM
#8
Hyperactive Member
Re: Set Text in textbox within an iframe
Did you also create the iframe code. if you want to set te textbox in your i frame you can change tha value of your iframe code.
-
Aug 25th, 2012, 11:15 PM
#9
Thread Starter
Addicted Member
Re: Set Text in textbox within an iframe
 Originally Posted by marniel647
Did you also create the iframe code. if you want to set te textbox in your i frame you can change tha value of your iframe code.
That's a good suggestion, but, I don't have any control over the iframe code.
-
Aug 27th, 2012, 11:29 AM
#10
Re: Set Text in textbox within an iframe
A web site's HTML code is usually specific to that website, and as dunfiddlin says it is difficult to produce generic code that interacts reliably with specific HTML when you don't know what that specific HTML is.
With that in mind, the following may work. Or it might not. Or it might do something totally unexpected. That said though, I have had it working with a textbox in an iFrame ... just not your textbox in your iFrame :P
vb.net Code:
Dim iFramesFound As Boolean = False ' (only used to give feedback)
Dim inputFound As Boolean = False ' (only used to give feedback)
'Find all the frames
Dim frames As HtmlWindowCollection = WebBrowser1.Document.Window.Frames
'check each frame for the element with id="element_2_1"
For f = 0 To frames.Count - 1
iFramesFound = True ' (feedback, remember?)
Dim frameDoc As HtmlDocument = WebBrowser1.Document.Window.Frames(f).Document
Dim frameEle As HtmlElement = frameDoc.GetElementById("element_2_1")
If frameEle IsNot Nothing Then
inputFound = True ' (also feedback, remember?)
frameEle.SetAttribute("value", "DDDD") ' write into the textbox
Exit For
End If
Next
'(here comes the feedback):-
Dim strMessage As String
strMessage = IIf(iFramesFound, "Found iFrames", _
"NO iFrames found").ToString
strMessage &= Environment.NewLine
strMessage &= IIf(inputFound, "and then found text input box", _
"and then failed to find text input box").ToString
MessageBox.Show(strMessage)
-
Aug 27th, 2012, 01:20 PM
#11
Thread Starter
Addicted Member
Re: Set Text in textbox within an iframe
Thank you for the example Inferred, I tried it but got an access error, added an "On Error Resume Next" since there were multiple frames, some of which were connected to a different host/site which likely caused the access error. But, it still did not take. I did however, figure out a different work around. I appreciate yours and marniel647's help.
-
Aug 28th, 2012, 10:27 AM
#12
Re: Set Text in textbox within an iframe
If by chance you have control over the content then I would suggest discarding the use of iframe and code the form in the same page. The code below may or may not be more than you are use too in regards to writing web content and if so there are plenty of sites that can assist with learning about css. Of course if you are not able to change how content is done the following is of no use.
I had a page done and tweaked it to use an iframe then without an iframe. The legend style is setup for IE and if was used in a production environment would have a css style sheet to determine the agent (browser) to conditionally style the legend. Also note for the div in the page with the iframe position is absolute while in the single page relative.
First example embeds another page in it via iframe while the second example does the same in a single page.
Example 1
Mainpage
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
</head>
<body>
<div style="position:absolute;top:100px;left:100px;">
<iframe src="./Page1.html" scrolling="No" frameborder="0" style="width: 548px; height: 150px"></iframe>
</div>
</body>
</html>
iframe for above
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>MSDN Site Search via Google</title>
<style media="screen" type="text/css">
fieldset
{
border: 1px solid #781351;width: 20em;
padding-left: 21px;
padding-bottom: 1em;
width:348px;
position:relative;
background-color: #ffff00;
}
/* legend, postion and top are IE tweaks to ensure background does not bleed */
legend {position: relative;top:-0.75em;color: #fff;background: #ffa20c;border: 1px solid #781351;padding: 2px 6px; margin-bottom:15px}
input {color: #781351;background: #fee3ad;border: 1px solid #781351;margin-bottom:10px;}
.submit input {color: #000;background: #ffa20f;border: 2px outset #d7b9c9}
span {margin-bottom:10px;color: #DEB887;vertical-align: top;}
</style>
<script language="javascript" type="text/javascript">
function MSDN_Site_Search()
{
document.write("<a HREF='http://www.google.ca/search?as_q=" + document.mainForm.inputtext1.value + "&as_epq=&as_oq=&as_eq=&as_nlo=&as_nhi=&lr=&cr=&as_qdr=all&as_sitesearch=http%3A%2F%2Fmsdn.microsoft.com&as_occt=any&safe=active&tbs=&as_filetype=&as_rights=' title='Return to home page'>" + document.mainForm.inputtext1.value + "</a>");
}
</script>
</head>
<body>
<form name="mainForm">
<fieldset>
<legend>MSDN Search</legend>
<input type="text" id="inputtext1" value="VB.NET" style="width: 300px;" />
<input type="button" value="GO" style="width:332px" onClick="MSDN_Site_Search();" style="width: 400px;">
</fieldset>
</form>
</body>
</html>
Single page, does same as above
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>MSDN Site Search via Google</title>
<style media="screen" type="text/css">
fieldset
{
border: 1px solid #781351;width: 20em;
padding-left: 21px;
padding-bottom: 1em;
width:348px;
position:relative;
left:100px;
top:100px;
background-color: #ffff00;
}
/* legend, postion and top are IE tweaks to ensure background does not bleed */
legend {position: relative;top:-0.75em;color: #fff;background: #ffa20c;border: 1px solid #781351;padding: 2px 6px; margin-bottom:15px}
input {color: #781351;background: #fee3ad;border: 1px solid #781351;margin-bottom:10px;}
.submit input {color: #000;background: #ffa20f;border: 2px outset #d7b9c9}
span {margin-bottom:10px;color: #DEB887;vertical-align: top;}
</style>
<script language="javascript" type="text/javascript">
function MSDN_Site_Search()
{
document.write("<a HREF='http://www.google.ca/search?as_q=" + document.mainForm.inputtext1.value + "&as_epq=&as_oq=&as_eq=&as_nlo=&as_nhi=&lr=&cr=&as_qdr=all&as_sitesearch=http%3A%2F%2Fmsdn.microsoft.com&as_occt=any&safe=active&tbs=&as_filetype=&as_rights=' title='Return to home page'>" + document.mainForm.inputtext1.value + "</a>");
}
</script>
</head>
<body>
<form name="mainForm">
<fieldset>
<legend>MSDN Search</legend>
<input type="text" id="inputtext1" value="VB.NET" style="width: 300px;" />
<input type="button" value="GO" style="width:332px" onClick="MSDN_Site_Search();" style="width: 400px;">
</fieldset>
</form>
</body>
</html>
-
Aug 28th, 2012, 03:26 PM
#13
Thread Starter
Addicted Member
Re: Set Text in textbox within an iframe
Thank you for the suggestion kevininstructor. that looks like a great solution, unfortunately, I do not have control over the server's code.
-
Aug 29th, 2012, 08:12 AM
#14
Re: Set Text in textbox within an iframe
 Originally Posted by SavedByGrace
Thank you for the suggestion kevininstructor. that looks like a great solution, unfortunately, I do not have control over the server's code.
Have you considered talking to the developer for this code?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|