Solved

Finding Frame Source name with Javascript

Posted on 2009-04-14
10
209 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
 
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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
 

Author Comment

by:rgarimella
ID: 24136595
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…

705 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now