Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8396411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:31:43+00:00 2026-06-09T20:31:43+00:00

I’m working on a page which is dynamically generated via a CGI system, where

  • 0

I’m working on a page which is dynamically generated via a CGI system, where the site’s real developer doesn’t have the time to make changes to the python code for me. That said, I’m forced to frame the page (same domain) and use some JavaScript to modify its contents… Right now, I’m trying to find anchor tags which contain a URL and set the target attribute to “_top”. This way, anchors on the page which open menus etc are loaded within the frame, and anything that points offsite is loaded in the overall window. Here’s what I’ve tried:

function pointOutside(){
    var anchorS = window.frames[0].document.getElementsByTagName("a");
    for(i=0;i<anchorS.length;i++){
        var foo = anchorS[i].getAttribute('href');
        foo = foo.toString();
        if(foo.search(/http/i) != -1){
            anchorS[i].setAttribute('target','_top');
        };
    };
};
setTimeout("pointOutside()",2000);

The timeout gives the frame’s contents sufficient time to load before it’s called, but where I’m running into trouble is checking the href property for whether or not it starts with “http”. I initially tried this without the “foo = foo.toString();” line, but was getting an error along the lines of “Uncaught TypeError: Cannot call method ‘search’ on null.” I thought to myself, “aha, I’ll make sure it’s a string!” but no luck. Now I’m getting a similar error when I call toString()… “Uncaught TypeError: Cannot call methor ‘toString’ of null.”

The odd thing is that, to make sure my selector was working, I used “alert(foo)” and was able to get a popup for each anchor tag showing the value for the href property.

Not sure where I’m going wrong here. Any help would be MUCH appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T20:31:44+00:00Added an answer on June 9, 2026 at 8:31 pm

    First off, if you have any javascript frameworks available in that browser window, take advantage of them by using a DOMReady function like jQuery’s .ready http://api.jquery.com/ready/

    Also, you’ll need to account for .href and .getAttribute(‘href’) returning different values. In Chrome for example, .href returns the url that will be navigated to if you clicked the link. .getAttribute(‘href’) however returns what’s actually in the anchor tag, which may be a relative url.

    Lastly, the reason you are getting the exception is that there are probably some anchors on the page that do not have an href and are there for purely structural purposes. For those elements, you could insert a line before you try and use .toString() like so:

    if (typeof foo !== "string") { continue; }
    

    The continue statement causes the for loop to ignore that link and move on to the next iteration of the loop if the href is not set on that link.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I have a text area in my form which accepts all possible characters from
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.