Solved

Finding Frame Source name with Javascript

Posted on 2009-04-14
10
219 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 500 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 500 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
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…

691 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