-1

Trying to select the following link in html:

<a href="/node/1742957/nodequeue">Nodequeue</a>

with this Javascript:

jQuery("a:contains('Nodequeue')").trigger("click");

And I am receiving this error message:

Javascript console (:1): Unsafe JavaScript attempt to access frame with URL http://cdn.nprove.com/cpma/p/1/2/e/b/12ebf3bc368ry3ra.html?npuid=1310010225&rurl=&id=cpma-2n7eypbvio581300288437193&null=&r=366424962878227 from frame with URL http://www.benzinga.com/analyst-ratings/analyst-color/11/07/1742957/the-beef-stops-here. Domains, protocols and ports must match.

Any idea what might cause this?

3
  • What is the code for this click event? Can you provide a sample? It will be really helpful. Commented Jul 8, 2011 at 4:07
  • I am doing it in a programmatic web browser module for Python - called Spynner, based on WebKit. The actual page is any of the articles at www.benzinga.com Commented Jul 8, 2011 at 13:14
  • Did my solution help you, are you planning on marking a solution? Commented Jul 8, 2011 at 23:08

2 Answers 2

1

I created a JSFiddle of your code which you can look at and notice that in the console your error doesn't come up in Chrome 12 or FireFox 5. I'm not sure what version of jQuery you are using that is causing that or your DOM situation that may be triggering that error, however, try this potential fix:

(function(window, $) {

  $.fn.triggerAnchor = function() {
    return this.each(function(e) {
      var href = $(this).attr('href');
      window.location.href = href;

      return false;
    });
  };

})(this, this.jQuery);

Then use with:

$("a:contains('Nodequeue')").triggerAnchor();

I don't think jQuery triggers anchors, and it certaintly doesn't trigger native click events. This is the closest thing I can think of to emulate that behavior.

You can see it 'working' here

Explanation of the code:

The code is simply a jQuery plugin that looks at the href attribute of anchor and sets the window location to that value. I wrote in the typical pattern of a wrapped closure to localize references to window and jQuery. I'm allowing you to call this on multiple anchors, but I'm assuming the average user would only need to run this once.

Sign up to request clarification or add additional context in comments.

Comments

1

That error usually means you are making a javascript request from one frame to another. In this case, is the link in an iframe, or is jquery running in an iframe?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.