0

I have this:

<td onclick="window.location='http://www.google.com/';"> </td>

The problem is that I have this inside an iframe, so onclick it opens in the iframe. How do I open this link on the parent page instead of the iframe?

(Is there a way to do this with one js script for all the links on the page?)

2 Answers 2

4
window.parent.location.href='http://www.google.com/';

and if you want to reload the top most window:

window.top.location.href='http://www.google.com/';
Sign up to request clarification or add additional context in comments.

2 Comments

Is there a difference in 'speed' between 'top' and 'parent' ?
@Youss, I don't think there will be any difference in speed. There is a difference in the behavior though.
1

one way to do this with on js script for all the links on the page is to add onClick event on the links when the page is loaded. here is a quick code. put this code in a file and put it in an iframe.

<html>
<script>
function openInParent() {
  window.parent.location = this.href;
  return false;
}

function doload () {
  // loop through all links in the page to add onclick event
  var links = document.getElementsByTagName ('a');
  for(i in links) {
    links[i].onclick = openInParent;
  }
}

window.onload = doload;
</script>
<body>
<a href="http://www.google.com">test</a>
</body>
</html>

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.