Finding Frame Source name with Javascript

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

rgarimellaAsked:
Who is Participating?
 
abelConnect With a Mentor Commented:
A simple greedy regexp will do the trick:

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

-- Abel --
0
 
abelCommented:
what about:

var framSrc = window.frames["Content"].src;
0
 
rgarimellaAuthor Commented:
returning Undefined

0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
rgarimellaAuthor Commented:
var frameSrc = Content.location.href

This actually gives me the entire path, i just need the filename
0
 
abelCommented:
almost correct, it should've been:

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

-- Abel --
0
 
abelCommented:
> This actually gives me the entire path, i just need the filename

ah, apologies, I posted too quickly. Hold on.
0
 
abelConnect With a Mentor Commented:
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
 
rgarimellaAuthor Commented:
Thanks, works like a charm.

I had to remove the extra ) in the end

RG
0
 
abelCommented:
> 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
 
rgarimellaAuthor Commented:
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.