3
document.location.href="http://verttgrettest.com/testpaper.aspx?VideoId=1"

Javascript how to add target="_parent" in document.location.href

3
  • You want to open a new window/tab? Commented Oct 13, 2012 at 17:38
  • yup in new iframe window Commented Oct 13, 2012 at 17:38
  • You would change the src attribute of the iframe in that case Commented Oct 13, 2012 at 17:39

4 Answers 4

6

You can't, the .href is literally just the URL you want to redirect to. You have to directly change the .href of the frame you want to target, not the href of the window/frame you're in e.g.

parent.document.location.href = 'http://...'
Sign up to request clarification or add additional context in comments.

1 Comment

so no need of adding a targe="_parent"
3
window.open(
  'http://verttgrettest.com/testpaper.aspx?VideoId=1',
  '_blank' 
);

2 Comments

your second parameter is way wrong developer.mozilla.org/en-US/docs/DOM/window.open
@naveen according to the doc you linked, this is correct : _blank is a valid window name. The proposed solution works in Chrome.
1

//but popup blocker may block it

window.open('http://verttgrettest.com/testpaper.aspx?VideoId=1')

1 Comment

And the second parameter to window.open would be "_parent"
0

I use the following codes:

if (parent)
    parent.document.location.href = '/iframe_parent';
else
    location.href = '/no_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.