0

I've got a page with many href links that open content within the frame (page does not reload, url remains the same, just new content). The problem I'm running into is that, since they are "href"s, the browser gives the option to open in a new tab/window on right click. But the response content is not designed to stand as its own page because it's supposed to be opened within the current frame.

Is there a way, for when the user wants to open in a new tab/window, to also include the current url first so that the href link functions correctly in the new tab/window? Hopefully I'm making sense.

One solution I'm exploring is to not use hrefs at all and just use jQuery to run the GET so that there isn't even an option to open in a new tab/window. But this would require a lot of changes to the current code, so I'm holding off for now.

royhowie
  • 11,075
  • 14
  • 50
  • 67
Jesse
  • 3
  • 1

2 Answers2

0

You can add javascript at the top of the page that should be in a frame to redirect to the top-level url if it is not within a frame. In this scenario, you probably want to include a parameter so that you know what page to load in the frame. E.g.:

if (window.parent == window.top) {
    window.location = "/toplevelurl?framepage=myframepage";
}
David Hammond
  • 3,286
  • 1
  • 24
  • 18
  • This more closely relates to my specific problem, but because of how the page is designed, I would have to programmatically navigate to a particular point on the page before setting the source of the iframe. Because of that of a few other factors, my team is leaning toward the "change them from href links to anchors with onclick methods" strategy. Thanks for your suggestion. – Jesse May 05 '15 at 01:17
0

You can use jQuery to add an event to your href which would handle your content and post html in a div or other area:

<html>
<head>
<meta charset="utf-8">
<title>Load remote content into object element</title>
</head>
<body>
<div id="siteloader"></div>​
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script>
  $("#siteloader").html('<object data="http://location-of-stuff/">');
</script>

Took this example from this post

Community
  • 1
  • 1
Pigasus
  • 130
  • 1
  • 2
  • 10