?
Solved

Finding Frame Source name with Javascript

Posted on 2009-04-14
10
Medium Priority
?
243 Views
Last Modified: 2012-05-06
Hi Folks,

I have the following FrameSet, see code.

I need to get the name of the Frame Src "ab_03_01_0010.htm" of the Content Frame via Javascript as this would be dynamic.

like

var frameSrc = Content.location.href

final output should be

frameSrc = "ab_03_01_0010.htm"

<frameset rows="100%,*" frameborder="no" border="0" framespacing="no" onLoad="getBookmarkCD();" onbeforeunload="bookmarkit();">
 
<frame src="ab_03_01_0010.htm" name="Content" title="Main Content" SCROLLING="no" MARGINWIDTH="0" MARGINHEIGHT="0" FRAMEBORDER="no" BORDER="0" noresize>
 
<frame src="bottomnav01.htm" name="Navigation" title="Navigation" SCROLLING="no" MARGINWIDTH="0" MARGINHEIGHT="0" FRAMEBORDER="no" BORDER="0" noresize>
 
</frameset>

Open in new window

0
Comment
Question by:rgarimella
  • 6
  • 4
10 Comments
 
LVL 39

Expert Comment

by:abel
ID: 24136405
what about:

var framSrc = window.frames["Content"].src;
0
 

Author Comment

by:rgarimella
ID: 24136413
returning Undefined

0
 

Author Comment

by:rgarimella
ID: 24136421
var frameSrc = Content.location.href

This actually gives me the entire path, i just need the filename
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 39

Expert Comment

by:abel
ID: 24136427
almost correct, it should've been:

var frameSrc = window.frames['Content'].location.href;

-- Abel --
0
 
LVL 39

Expert Comment

by:abel
ID: 24136431
> This actually gives me the entire path, i just need the filename

ah, apologies, I posted too quickly. Hold on.
0
 
LVL 39

Accepted Solution

by:
abel earned 2000 total points
ID: 24136477
A simple greedy regexp will do the trick:

   var frameSrc = window.frames['Content'].location.href.replace(/.*\/(.*)$/, '$1'));

-- Abel --
0
 
LVL 39

Assisted Solution

by:abel
abel earned 2000 total points
ID: 24136490
a little explanation: the regular expression will grab as much as possible and then backtracks to the last slash ("/") of the pathname (needed to be escaped as \/ in the regex). It captures the rest in (.*) as $1 and finally anchors it to the end of the string with "$" to make the sure the regex works as intended.

The replacement string replaces everything for what is inside the brackets.

-- Abel --
0
 

Author Comment

by:rgarimella
ID: 24136496
Thanks, works like a charm.

I had to remove the extra ) in the end

RG
0
 
LVL 39

Expert Comment

by:abel
ID: 24136573
> I had to remove the extra ) in the end

a, apologies, that was the left-over bracket of my alert(...) statement to test it, copy-n-paste error :/
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question