?
Solved

Finding Frame Source name with Javascript

Posted on 2009-04-14
10
Medium Priority
?
236 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
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…

650 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