Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get iframe name 1

Status
Not open for further replies.

Ruriko

Programmer
Aug 17, 2012
7
Hi I'm a newbie at javascript and I was wondering how can I extract the iframe name using regex only? so for example if the string value contains:
Code:
<DIV style="MARGIN-TOP: 0px; WIDTH: 670px; HEIGHT: 210px; VISIBILITY: visible; MARGIN-LEFT: -335px; TOP: 48px" id=TB_window><DIV id=TB_title>  <DIV id=TB_ajaxWindowTitle>Add Media</DIV>  <DIV id=TB_closeAjaxWindow><A id=TB_closeWindowButton title=Close href="#" jQuery172014112867239284427="140"><IMG src="[URL unfurl="true"]http://www.gorgeoushentai.com/wp-includes/js/thickbox/tb-close.png"></A></DIV></DIV><IFRAME[/URL] style="WIDTH: 670px; HEIGHT: 180px" id=TB_iframeContent onload=tb_showIframe() src="[URL unfurl="true"]http://www.gorgeoushentai.com/wp-admin/media-upload.php?post_id=168&"[/URL] frameBorder=0 name=TB_iframeContent656 hspace=0>This feature requires inline frames. You have iframes disabled or your browser does not support them.</IFRAME></DIV>
then it would extract TB_iframeContent656
 
Hi

For your sample input this will work, but note that regular expressions are not suitable for parsing complex structured data :
JavaScript:
matchlist[teal]=[/teal]yourstring[teal].[/teal][COLOR=darkgoldenrod]match[/color][teal]([/teal][fuchsia]/<iframe\b[^>]+\bname=["']?(.+?)\b/i[/fuchsia][teal])[/teal]
[b]if[/b] [teal]([/teal]matchlist[teal])[/teal] iframename[teal]=[/teal]matchlist[teal][[/teal][purple]1[/purple][teal]][/teal]

Feherke.
[link feherke.github.com/][/url]
 
Using a regular expression seems a little arcane, bordering on bizarre to say the least.

surely
JavaScript:
var IFname = document.getElementsByTagName('iframe')[0].name;
would do perfectly well. Assuming ther is only one iFrame which your question does imply.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
True, but tempered with the the point that javascript and iframes are only likely to occur in the context of a web browser, it seems like a reasonable assumption that the TS as a
Ruriko said:
newbie at javascript
is asking the wrong question.


And then the number of time it has asked the same question and the wording it may also be a coursework question from yet another lazy student.


Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
AND

there is this one, thread329-1696839 lurking in the vBScript board which I hadn't even noticed was by the same person, it all smells rather "studenty" to me.



Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top