Solved

Finding Frame Source name with Javascript

Posted on 2009-04-14
10
215 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
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
 

Author Comment

by:rgarimella
ID: 24136595
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to make a moving character 3 62
Converting dates in JavaScript 2 37
Html5 Index on a table 7 29
Jquery Validation Messages Not Showing Up 3 16
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
This article discusses how to create an extensible mechanism for linked drop downs.
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…

825 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